2017-05-04 262 views
0

我似乎無法讓路由正常工作。當我跑步時,我還包括了collectstaticdjango用nginx提供靜態文件

在我settings.py我有如下代碼

STATIC_URL = '/static/' 
STATIC_ROOT = "/code/static" 

在我的nginx的配置文件

worker_processes 1; 

events { 

    worker_connections 1024; 

} 

http { 

    server { 
     listen 80; 
     server_name example.org; 

     access_log /dev/stdout; 
     error_log /dev/stdout info; 

     location /static/ { 
      autoindex on; 
      root /code; 
     } 


     location/{ 
      proxy_pass http://web:8000; 
      proxy_set_header Host $host; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
      proxy_set_header X-Forwarded-Host $server_name; 
     } 
    } 
} 

錯誤日誌

2017/05/04 13:14:54 [error] 5#5: *1 open() "/code/static/css/bootstrap.min.css" failed (2: No such file or directory),client: 172.18.0.1, server: example.org, request: "GET /static/css/bootstrap.min.css HTTP/1.1", host: "localhost", referrer: "http://localhost/polls/" 

服務器目錄

[email protected]:/# cd /code/static 
[email protected]:/code/static# ls -l 
total 16 
drwxr-xr-x 6 root root 4096 May 4 13:40 admin 
drwxr-xr-x 2 root root 4096 May 4 13:40 css 
drwxr-xr-x 2 root root 4096 May 4 13:40 fonts 
drwxr-xr-x 2 root root 4096 May 4 13:40 scripts 
[email protected]:/code/static# 

回答

0

你的STATIC_ROOT是「/ code/static」,但是你的nginx配置映射/ static /到「/ code」。這些應該是一樣的。

+0

你能具體談談什麼,我需要改變嗎? – root

0

嘗試位置更新nginx的配置文件:靜態部分,這

... 
location /static/ { 
    autoindex on; 
    alias /code/static/; 
} 
... 

FYI deploy django with nginx

+0

也不起作用。 – root