2013-07-17 110 views
0

我遵循的教程,我在這裏找到,當我試圖訪問靜態文件,我得到一個頁面找不到錯誤。這裏是我正在遵循的教程https://gist.github.com/evildmp/3094281無法弄清楚如何使用Nginx提供靜態文件

這是在nginx的錯誤日誌文件中。 2013年7月17日九時55分15秒[EMERG] 2891#0: 「上游」 指令,在這裏不允許使用在/etc/nginx/nginx.conf:2

,這是我的nginx的conf文件

# 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

你錯過了一個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 
      } 
     } 


} 
+0

提供了一些默認我也覺得我是做編輯的nginx.conf的錯誤nginx文件,而不是在站點可用這是正確的或不正確的? – user2482595

+0

最有可能。您不需要使用可用的網站。如果您想要在路上添加某些內容,在_sites-available_中管理這些內容會更容易。如果您決定使用_sites-available_,請確保將/etc/nginx/nginx.conf文件重置爲默認值。 此外,如果這回答你的問題,一定要將它標記爲這樣。 –