2017-01-20 27 views
0

nginxとuwsgiを使用してdjangoアプリを使用しています。私の静的ファイルは404を返します。ファイルの所有権をnginxユーザー名に対応するように設定しました。静的フォルダへのパスは端末から直接コピーされ、私はcollectstaticを実行しました(静的ファイルはdjango開発サーバ経由で正常に処理されています)。また、私は、エイリアスとルートの両方を試してみました静的ファイルのdjango + nginx + uwsgi 404

chown -R username:username /home 

chmod -R ug+r /home 

を実行しました。

STATIC_ROOTは、ここに私のsettings.pyに

STATIC_ROOT = os.path.join(BASE_DIR, "static/") 

である私のnginx.confです:

user username; 
worker_processes 1; 

events { 

    worker_connections 1024; 

} 

http { 

    sendfile on; 

    gzip    on; 
    gzip_http_version 1.0; 
    gzip_proxied  any; 
    gzip_min_length 500; 
    gzip_disable  "MSIE [1-6]\."; 
    gzip_types  text/plain text/xml text/css 
         text/comma-separated-values 
         text/javascript 
         application/x-javascript 
         application/atom+xml; 

    # Configuration containing list of application servers 
    upstream app_servers { 

     server 127.0.0.1:8080; 
     # server 127.0.0.1:8081; 
     # .. 
     # . 

    } 

    # Configuration for Nginx 
    server { 

     # Running port 
     listen 80; 

     # Settings to serve static files 
     location /static/ { 

      # Example: 
      # root /full/path/to/application/static/file/dir; 
      alias /home/myapp/myapp/static/; 

     } 

     # Serve a static file (ex. favico) 
     # outside /static directory 
     location = /favico.ico { 

      root /app/favico.ico; 

     } 

     # Proxy connections to the application servers 
     # app_servers 
     location/{ 

      proxy_pass   http://app_servers; 
      proxy_redirect  off; 
      proxy_set_header Host $host; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_set_header X-Forwarded-Host $server_name; 

     } 
    } 
} 
+0

あなたのプロジェクトの完全なパスは何ですか? – petkostas

+0

/home/username/uswgi-tutorial/mysite – skeletonsaurus

答えて

0

それは一部のユーザーに/homeディレクトリをchownコマンドに悪い考えです。そのディレクトリはrootに属している必要があります。バックそれが何であったかのように変更します。

chown root:root /home 
chmod u=rwx,g=rx,o=rx /home 

を(あなたが実行したchmodのは、おそらくその権限が変更されていないが、より良いので、それが何だったかにそれを戻り上述した第2のコマンド、特定のことがしました。)

あなたのプロジェクトは/home/usernameですが、nginxの設定では/home/myappとなっています。それを修正してください。私はそれが/home/usernameと仮定します。 /home/usernameは、いくつかの権限を修正する必要があります。

chmod o+rx /home/username 

http://djangodeployment.com/2016/11/21/how-django-static-files-work-in-production/(私の記事)も参照してください。

関連する問題