2015-12-29 114 views
1

我跟着this tutorial爲了讓我的Django應用程序部署在DigitalWater VPS與uWSGI和Nginx。靜態文件運行良好,但Django應用程序本身沒有。 (404未找到 - nginx的/ 1.9.6)Nginx響應404 Django應用程序,但靜態文件工作

# Where to look for content (static and media) 
root /srv/www/$host/; 

# Allow gzip compression 
gzip_types text/css application/json application/x-javascript; 
gzip_comp_level 6; 
gzip_proxied any; 
# Look for files with .gz to serve pre-compressed data 
gzip_static on; 

server {   
    listen 80; 
    # nginx docs recommend try_files over "if" 
    location / { 
     # Try to serve existing files first 
     try_files $uri @proxy =404; 
    } 
    location @proxy { 
     # Pass other requests to uWSGI 
     uwsgi_pass unix://srv/apps/_/server.sock; 
     include uwsgi_params; 
    } 
} 
+0

確保套接字'/ srv/apps/_/server.sock'存在。如果沒有,請檢查您的uWSGI配置。 – GwynBleidD

+0

你的'try_files'的語法是錯誤的。 '@ proxy'或'= 404'應該是最後一個元素 - 你不能同時擁有這兩個元素。請參閱[本文檔](http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files) –

+0

存在'/ srv/apps/_/server.sock'。 –

回答

2

try_files目的是測試一個本地文件的存在,並且如果沒有發現執行默認動作。就你而言,該默認操作是調用名爲@proxy的指定位置。這是你所需要的:

location/{ 
    try_files $uri @proxy; 
} 
location @proxy { 
    uwsgi_pass unix://srv/apps/_/server.sock; 
    include uwsgi_params; 
} 

詳見this document

相關問題