I’ve was following This article of digital ocean https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04
I was able to setup flask, gunicorn, Nginx correctly but any request to my server Nginx routes to default Nginx home page rather forwarding to my app. It’s been three days since I am debugging this but not able to solve this.
Some difference between my setup vs this article mentions is,
rest is same. Its not showing any error also so I am not sure what is happening, any help is welcomed
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!
Saw in another place an answer that MAY help - not sure. In Django, there’s a ALLOWED_HOSTS configuration parameter which needs to have the domain name. I’m not sure if Flask has that or not - apologies. If it does, check that out.
Hi :)
First off, good job on getting this far. Just FYI, many of the more popular tutorials have versions for different platforms, eg, there is a version of that tutorial for Centos 7 here:
OK, so in the nginx config, for server_name you put your public Droplet IP? That’s in this section of the tutorial, https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-centos-7#configuring-nginx-to-proxy-requests.
At the end of that section there’s a couple of commands to start and enable this config - were you able to run those? If nginx is already running, you may need to restart it like:
sudo systemctl restart nginx
Hope this helps, let us know how it goes.
Heya,
First make sure you’ve added your Droplet’s IP address and your domain name + www.domain.name to your Allowed Hosts in the settings.py file.
Next, you can use this nginx config as an example of how to configure nginx so that it works
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
# Redirect HTTP to HTTPS (Optional, if using SSL)
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name yourdomain.com www.yourdomain.com;
# SSL Configuration (Optional, if using SSL)
ssl_certificate /etc/ssl/certs/yourcert.pem;
ssl_certificate_key /etc/ssl/private/yourkey.key;
location / {
proxy_pass http://127.0.0.1:8000; # The Gunicorn server
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Static files
location /static {
alias /path/to/your/flask/app/static;
}
# Log files (Optional)
access_log /var/log/nginx/yourapp_access.log;
error_log /var/log/nginx/yourapp_error.log;
}
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.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.