Question

Trying to run Nginx with Ubuntu / Python /Django only results in 404 error

Posted April 13, 2020 340 views
Nginx

Hi, I have set up Ubuntu, Python3.7, Django3.0.2 and Postgres as per the DigitalOcean tutorial on a DigitalOcean server. Gunicorn works and the Nginx server loads but only gets a 404 error from the browser. Has anyone had this error and fixed it, or is there a tutorial I can refer to. I’m new to Nginx. Thanks

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.

×
1 answer

Hi @peterdp,

It seems you haven’t configured your server blocks in Nginx properly. DigitalOcean have a pretty good tutorial how to do that. You can check that here :

https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-16-04

Additionally, there is another article which can help you with your problem. It’s about configuring Django with Nginx. You can view that here as well

https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-14-04

If you experience issues with your application after you’ve checked both articles. Please post your Nginx virtual file for your domain here.

Regards,
KDSys

by Justin Ellingwood
Django is a powerful web framework that can help you get your Python application or website off the ground. Django includes a simplified development server for testing your code locally, but for anything even slightly production related, a more secure and powerful web server...
  • Hi - thanks for the help!
    Went through the second tutorial (had to do a bit of updating to use systemctl rather than .service) but gor both nginx and uwsgi running. Using the python localhost the page and admin page are fine, but the nginx/uwsgi set up results in a 404 error again. Which is the Nginx virtual file you refer to?

    Best regards

    • Hi @peterdp,

      The Nginx virtual file I meant is the domain configuration located here

      /etc/nginx/sites-available/example.com
      

      Ofcourse, please remember to change example.com with your actual domain.

      You’ll need to add the configuration there.

      Regards,
      KDSys

Submit an Answer