0
I am following this tutorial https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-16-04
I am deploying django/react app on digital ocean ubuntu, for this i have made one project and running whole app through django by creating build folder, everything is fine, i create build folder, run django server using python manage.py runserver 0.0.0.0:8000 and app loads perfectly, but when i run my server through gunicorn using command gunicorn --bind 0.0.0.0:8000 mobilehut.wsgi, server runs successfully but template doesn’t load means react frontend doesn’t load and i got blank page.
I have created a new user and then deployed, i am not using root. I can’t find what the problem is with gunicorn as its my first time. Can someone please suggest me what to check, is there is wsgi.py issue or some other like of nginx file.
Wsgi.py file:
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault(‘DJANGO_SETTINGS_MODULE’, ‘mobilehut.settings’)
application = get_wsgi_application()
Nginx file:
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
I am deploying django/react app on digital ocean ubuntu, for this i have made one project and running whole app through django by creating build folder, everything is fine, i create build folder, run django server using python manage.py runserver 0.0.0.0:8000 and app loads perfectly, but when i run my server through gunicorn using command gunicorn --bind 0.0.0.0:8000 mobilehut.wsgi, server runs successfully but template doesn’t load means react front doesn’t load and i got blank page.
I have created a new user and then deployed, i am not using root. I can’t find what the problem is with gunicorn as its my first time. Can someone please suggest me what to check, is there is wsgi.py issue or some other like of nginx file.
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault(‘DJANGO_SETTINGS_MODULE’, ‘mobilehut.settings’)
application = get_wsgi_application() Do we need to check this ? /etc/nginx/sites-enabled/default, in this i tried to access with new user -> root var/www/html , it shows permission denied , is that a issue
server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
} kindly suggest some solution, my app runs fine with this python manage.py runserver 0.0.0.0:8000 , but not with gunicorn --bind 0.0.0.0:8000 server loads but blank white page.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Heya,
Check the browser’s console for any JavaScript errors. A blank page could indicate a JavaScript error on the client side.
Also, check both Gunicorn and Nginx error logs for any issues. You can find Gunicorn logs in your project directory or specify a log file using the --error-logfile option when starting Gunicorn. Nginx logs are typically located in /var/log/nginx/.
We have an updated article on How To Set Up Django with Postgres, Nginx, and Gunicorn on Ubuntu 22.04 which you can check here:
Regards
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.