2012-01-26 32 views
0

喜試圖獲得的nginx + gunicorn + Django的網站運行起來/它運作良好,在發展模式沒有錯誤或以下PARAMS anything.configured nginx的部署Pinax與gunicorn和nginx的不是靜態資產

upstream my-backend { 
    server localhost:8000 fail_timeout=0; 
} 

server { 
    listen 80; 

    root /home/wakwanza/Cod/NP/ASUT; 

    keepalive_timeout 5; 

    location /site_media/ { 
    autoindex on; 
     access_log off; 
    } 

    location /static/ { 
    autoindex on; 
     access_log off; 
    } 

    location/{ 
     proxy_set_header Host    $host; 
     proxy_set_header X-Real-IP  $remote_addr; 
     proxy_set_header REMOTE_HOST  $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header X-FORWARDED-PROTOCOL $scheme; 

    proxy_redirect off; 

     proxy_pass http://my-backend; 
    } 
} 

我gunicorn正在從與Django應用程序中調用: 蟒收集我的靜態文件到後manage.py run_gunicorn 我這樣做.../ASUT/site_media /靜態 只適用於開發模式壽。 我試圖與

location /static/ { 
    autoindex on; 
     access_log off; 
alias /home/wakwanza/Cod/NP/ASUT/site_media/; 
    } 

替代的位置指令,但我的靜態資產仍然沒有歌廳提供的所有的CSS/JS/img目錄的arent得到見過但是對於普通的網站他們出現確定的管理部分。

回答

2

排序它在settings.conf

STATIC_URL = "/static/" 

和nginx.conf更改爲

upstream app_server { 
    server localhost:8000 fail_timeout=0; 
    # For a TCP configuration: 
    # server 192.168.0.7:8000 fail_timeout=0; 
} 

server { 
    listen 80 default; 
    client_max_body_size 4G; 
    server_name _; 

    keepalive_timeout 5; 

    # path for static files 
    #root /home/wakwanza/Cod/NP/ASUT/site_media/static; 

    location /static/ {  
    autoindex on;  
    alias /home/wakwanza/Cod/NP/ASUT/site_media/static/;  
    } 

    location/{ 
     # checks for static file, if not found proxy to app 
     try_files $uri @proxy_to_app; 
    } 

    location @proxy_to_app { 
     proxy_pass_header Server; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
     proxy_set_header Host $http_host; 
     proxy_redirect off; 

     proxy_pass http://app_server; 
    } 

    error_page 500 502 503 504 /500.html; 

} 
+0

謝謝,這解決了404錯誤與我的靜態文件。 – 2012-02-21 00:52:07