无法弄清楚如何使用Nginx提供静态文件

时间:2013-07-17 17:22:23

标签: nginx uwsgi

我已经按照我在此处找到的教程进行操作,当我尝试访问静态文件时,我发现找不到页面错误。这是我关注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
    }
}

感谢您提供任何帮助或建议。

1 个答案:

答案 0 :(得分: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
            }
        }


}