Domanda

Ciao cercando di ottenere un sito Nginx + Gunicorn + Django, funzionante / funziona bene in modalità di sviluppo Nessun errore o qualsiasi cosa. Configurato il nginx per la distribuzione con i seguenti parametri

    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;
    }
}
.

Il mio Gunicorn viene chiamato dall'interno dell'App Django con: Python gestisci.py run_gunicorn. L'ho fatto dopo aver raccolto i miei file statici in ... / Asut / Site_media / Static funziona solo nel modo di dev. Ho provato a sostituire la direttiva sulla posizione con

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

Ma i miei beni statici non stanno ancora ottenendo serviti tutte le cartelle CSS / JS / IMG non vengono visualizzate per il sito normale tuttavia per la sezione di amministrazione che presentano OK.

È stato utile?

Soluzione

sorted it by changing in settings.conf

STATIC_URL = "/static/"

and nginx.conf to

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;

}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top