Denis Steinman
Denis Steinman

Reputation: 7799

django /admin not found

I try to setup Nginx+Gunicorn and when I go by my URL the Nginx redirects request to my app and handles it by itsels for static resource (static folder). Below my Nginx domain config:

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

The problem that I need to Nginx handles request by itself for static only (www.asknow.local/static) but it tries to handle other URLs too. So when I go to www.asknow.local/admin now Nginx tries to find a resource by path (my_project/admin). But if I go to www.asknow.local Nginx proxies a request to the Gunicorn. Gunicorn error log is empty, so it fails on Nginx side.

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"

How to fix it?

Upvotes: 0

Views: 697

Answers (1)

Tarun Lalwani
Tarun Lalwani

Reputation: 146630

Your issue is using =, that is use for absolute locations. You don't want that (only for favicon.ico) you want that

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

Upvotes: 2

Related Questions