Question

Django - The requested resource was not found on this server

Posted January 11, 2022 169 views
NginxDjango

I’ve installed Django, Nginx, Gunicorn and was able to get the default Django page when I had DEBUG = True. However, now I Have DEBUG = False and the page displays: The requested resource was not found on this server. I have the following in my configuration:

abcproject
–abcweb
—settings.py
—wsgi.py
—urls.py
–manage.py
–static
–templates
–venv
–app
.env

The app is the Django application. I have setup all the files I had in development for the app. That is the app I want displayed as the main website. Within app, I have templates, views, models, etc.

I have a .env file with environment variables. Here is an excerpt of my wsgi.py within –abcweb

import os
from django.core.wsgi import getwsgiapplication

os.environ.setdefault(‘DJANGOSETTINGSMODULE’, 'abcweb.settings’)

application = getwsgiapplication()

Here is my nginx configuration:

server {
server_name domain.com www.domain.com;

location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
    root /home/user/abcproject;
}

location / {
    include proxy_params;
    proxy_pass http://unix:/run/gunicorn.sock;        
}

listen 443 ssl; # managed by Certbot
#info managed by certbot -- removed for privacy

}
server {
if ($host = www.domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot

if ($host = domain.com) {
    return 301 https://$host$request_uri;
} # managed by Certbot


listen 80;
server_name domain.com www.domain.com;
return 404; # managed by Certbot

And the following is my Gunicorn configuration:

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

[Service]
User=pyxis
Group=www-data
WorkingDirectory=/home/user/abcproject
ExecStart=/home/user/abcproject/venv/bin/gunicorn \
–access-logfile - \
–workers 3 \
–bind unix:/run/gunicorn.sock \
abcweb.wsgi:application

[Install]
WantedBy=multi-user.target

I tried running:
gunicorn -b 0.0.0.0:8000 abcweb.wsgi:application

It runs with no errors, but still yields the page The requested resource was not found on this server.

Any ideas would be much appreciated.

1 comment

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer
Show answer This answer has been marked as resolved by mpasquali.