0

我遵循了我在此处找到的教程,当我尝试访问静态文件时,我得到一个找不到页面的错误。这是我关注的教程https://gist.github.com/evildmp/3094281

这是在 nginx 的错误日志文件中。2013/07/17 09:55:15 [emerg] 2891#0:/etc/nginx/nginx.conf:2 中不允许“上游”指令

这是我的 nginx 配置文件

# nginx.conf
upstream django {
# connect to this socket
# server unix:///tmp/uwsgi.sock;    # for a file socket
server 127.0.0.1:8000;      # for a web port socket was 8001
}

server {
# the port your site will be served on
listen      8000;
# the domain name it will serve for
server_name inventory.ien.gatech.edu;   # substitute your machine's IP address or FQDN
charset     utf-8;

#Max upload size
client_max_body_size 75M;   # adjust to taste

 # Django media
location /media  {
            alias /Desktop/Projects/Newest/IEN_Inventory/Inventory/templates/media;      # your Django project's media files
}

    location /static {
            alias /Desktop/Projects/Newest/IEN_Inventory/Inventory/templates/media;    # your Django project's static files
    }

# Finally, send all non-media requests to the Django server.
location / {
    uwsgi_pass  django;
    include     /etc/nginx/uwsgi_params; # or the uwsgi_params you installed manually
    }
}

感谢您的任何帮助或建议。

4

1 回答 1

1

你错过了一个 http 块。您的上游服务器块需要由http块包装。您的最终文件将如下所示。

编辑:我还添加了一些通常随 /etc/nginx/nginx.conf 提供的默认值

worker_process = 1;

events {
    worker_connections 1024;
}

http {
    include mime.types.default;
    # server_tokens off;    # Optional

    # sendfile on;          # Optional
    # keepalive_timeout 100;# Optional
    # tcp_nodelay on;       # Optional


    # nginx.conf
    upstream django {
        # connect to this socket
        # server unix:///tmp/uwsgi.sock;    # for a file socket
        server 127.0.0.1:8000;      # for a web port socket was 8001
    }

    server {
        # the port your site will be served on
        listen      8000;
        # the domain name it will serve for
        server_name server.servername.com;   # substitute your machine's IP address or FQDN
        charset     utf-8;

        #Max upload size
        client_max_body_size 75M;   # adjust to taste

         # Django media
         location /media  {
            alias /Desktop/Projects/Newest/Inventory/Inventory/templates/media;      # your Django project's media files
         }

         location /static {
            alias /Desktop/Projects/Newest/Inventory/Inventory/templates/media;    # your Django project's static files
        }

        # Finally, send all non-media requests to the Django server.
        location / {
            uwsgi_pass  django;
            include     /etc/nginx/uwsgi_params; # or the uwsgi_params you installed manually
            }
        }


}
于 2013-07-17T21:04:39.450 回答