1

Amazon EC2 で Django プロジェクトをホストする際に問題が発生しています。Gunicorn と Nginx を使用してサイトをホストしている場合、ブラウザーでページを読み込もうとすると、次のエラーが表示されます (Javascript コンソールからの抜粋)。

Failed to load resource: the server responded with a status of 504 (Gateway Time-out): https://example.com/favicon.ico 

Nginx には静的ファイルの検索に問題があると思いますが、その理由はわかりません。これが私のNginx構成です:

server {
    listen 443 default;
    client_max_body_size 100M;
    server_name www.example.com;

    keepalive_timeout 5;

    ssl on;
    ssl_certificate /etc/letsencrypt/live/www.example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/www.example.com/privkey.pem;

    # the domain name it will serve for
    charset     utf-8;

    # path for static files
    root /opt/app/staticfiles;

    location /static {
        root /opt/app/staticfiles;
    }

    location / {
        # checks for static file, if not found proxy to app
        try_files $uri @proxy_to_app;
    }

    location @proxy_to_app {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;

        proxy_pass   http://app_server;
    }

}

/var/log/nginx/access.log と cat /var/log/nginx/error.log には何も表示されません。

HTTP コード 504 の場合、通常、長いリクエストがハングして最終的にタイムアウトになることが問題ですが、サイトを読み込もうとしているだけなので、プロジェクトにどのように適用されるかわかりません。

この問題をデバッグする方法がわからないので、助けていただければ幸いです。

4

1 に答える 1

0

これはあなたを助けるかもしれません:

私がしたことは/etc/nginx/site-enabled/default、次のようにファイルを編集したことです。

server {
        #nginx server configuration 
        listen 80 default_server;
#       listen [::] default_server ipv6only=on;
        listen [::]:80 default_server ipv6only=on;

        root /usr/share/nginx/html;
        index index.html index.htm;

        # Make site accessible from http://localhost/
#       server_name localhost;
        # provide whole path of static files you got after running `python manage.py collectstatics`
        location /static{
                 alias /home/ubuntu/folder1/folder2/webpage/static;
        }

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                proxy_pass http://0.0.0.0:8134;#Provide your django server's link
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
}

: - 完了していることを確認してくださいpython manage.py collectstatics。nginx.conf ファイルを変更しないでください

于 2016-11-15T07:22:35.350 に答える