2017-11-01 7 views
0

ich Setup versuchen Nginx + Gunicorn und wenn ich durch meine URL gehen die Nginx leitet Anfrage an meine App und behandelt sie durch itsels für statische Ressource (static Ordner). Im Folgenden meine Nginx Domain config:django/admin nicht gefunden

server { 
     listen 80; 
     server_name asknow.local www.asknow.local; 

     root /home/ghostman/Projects/asknow/asknow; 

     location = /favicon.ico { access_log off; log_not_found off; } 
     location = /static/ { 
       root /home/ghostman/Projects/asknow/asknow; 
     } 
     location =/{ 
       include proxy_params; 
       proxy_pass http://unix:/home/ghostman/Projects/asknow/asknow/asknow.sock; 
     } 
} 

Gunicorn Daemon:

[Unit] 
Description=gunicorn daemon 
After=network.target 

[Service] 
User=ghostman 
Group=www-data 
WorkingDirectory=/home/ghostman/Projects/asknow/asknow 
ExecStart=/home/ghostman/Projects/asknow/env/bin/gunicorn --access-logfile /home/ghostman/Projects/asknow/env/log/gunicorn.log --error-logfile /home/ghostman/Projects/asknow/env/log/gunicorn-error.log --workers 3 --bind unix:/home/ghostman/Projects/asknow/asknow/asknow.sock asknow.wsgi:application 

[Install] 
WantedBy=multi-user.target 

Das Problem, das ich brauchen nginx Griffe Anfrage von selbst für static nur (www.asknow.local/static), aber er versucht, andere zu handhaben URLs auch. Also, wenn ich gehe www.asknow.local/admin jetzt Nginx versucht, eine Ressource nach Pfad (my_project/admin) zu finden. Aber wenn ich gehe zu www.asknow.local Nginx Proxies eine Anfrage an die Gunicorn. Das Gunicorn-Fehlerprotokoll ist leer, daher schlägt es auf der Nginx-Seite fehl.

Nginx log

2017/11/01 04:27:22 [error] 13451#13451: *1 open() "/usr/share/nginx/html/static/img/search.svg" failed (2: No such file or directory), client: 127.0.0.1, server: asknow.local, request: "GET /static/img/search.svg HTTP/1.1", host: "www.asknow.local" 

Wie es zu beheben?

Antwort

1

Ihr Problem verwendet =, das für absolute Standorte verwendet wird. Das möchten Sie nicht (nur für favicon.ico) wollen Sie das

server { 
     listen 80; 
     server_name asknow.local www.asknow.local; 

     root /home/ghostman/Projects/asknow/asknow; 

     location = /favicon.ico { access_log off; log_not_found off; } 
     location /static/ { 
       root /home/ghostman/Projects/asknow/asknow; 
     } 
     location/{ 
       include proxy_params; 
       proxy_pass http://unix:/home/ghostman/Projects/asknow/asknow/asknow.sock; 
     } 
} 
Verwandte Themen