簡體   English   中英

Pinax與gunicorn和nginx不提供靜態資產

[英]Pinax with gunicorn and nginx not serving static assets

嗨試圖讓nginx + gunicorn + django網站啟動並運行/它在開發模式下運行良好沒有錯誤或任何事情。配置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應用程序中調用的:python manage.py run_gunicorn我在將我的靜態文件收集到... / ASUT / site_media / static之后這樣做只能在開發模式下工作。 我試過替換location指令

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

但我的靜態資產仍未提供服務所有css / js / img文件夾都沒有被正常網站看到,但對於管理部分,他們顯示確定。

通過在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;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM