2017-05-04 11 views
0

ルーティングが正しく動作するように見えませんでした。私はcollectstaticも含めて走った。私settings.pydjangoがnginxで静的ファイルを提供しています

私は私のnginxの設定ファイルに次のコード

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

を持って

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/" 

Serverディレクトリ

[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

関連する問題