Redirect default (80) port to 5000 - Flask + NGINX + Ubuntu

Redirect default (80) port to 5000 - Flask + NGINX + Ubuntu



I'm successfully able to run a flask app on my IP:5000 path. A simple Hello World program that shows the output on my browser.
Now, what I would like to do is to configure NGINX with a proxy so that if I access only IP which apparently runs on a default port 80, it should navigate to port 5000 and show output of my application.


Hello World



In other words...
This is working : IP:5000 -> Output = Hello world
This isn't working: IP -> This site can’t be reached



The server settings that I want to add would be something like this.


server
listen 80;
server_name MY_IP;

location /
proxy_pass http://127.0.0.1:5000;




However, I'm not sure where to add this? Should it be inside http block inside /etc/nginx/nginx.conf?


http


/etc/nginx/nginx.conf



Updates: Based on the answers given below, I've managed to do the following.



enter image description hereenter image description here



I did restart nginx after this. However, I'm still facing the same issue. App works on IP:5000 but does not work on IP




3 Answers
3



The configuration you have mentioned should be in a separate file, assume example.com.conf under /etc/nginx/conf.d. You can put all the configuration in /etc/nginx/nginx.conf and it'll work, it's just that for readability we create separate configuration files which would be auto included when you add it inside conf.d.


example.com.conf


/etc/nginx/conf.d


/etc/nginx/nginx.conf


conf.d





I've updated my question.
– Abhilash
Aug 31 at 8:42



Ok, the problem is fixed. As @senaps and @Mukanahallipatna had mentioned, I created the new configuration file under conf.d.



However, the most imp step that I was missing was this part mentioned in the below link.



It is recommended that you enable the most restrictive profile that will still allow the traffic you've configured. Since we haven't configured SSL for our server yet, in this guide, we will only need to allow traffic on port 80.



Reference Link


sudo ufw allow 'Nginx HTTP'



Now, everything is working fine.



Put the working blocks in a file with any_name.conf inside the folder named /etc/nginx/conf.d and it will be loaded automatically.


any_name.conf


/etc/nginx/conf.d



You will need to restart your nginx.


nginx



update:
What are you using to serve flask? if you are using uwsgi, then you should use configurations like this:


flask


uwsgi


include uwsgi_params;
uwsgi_pass unix:path_to_your.sock;



Other options for uwsgi_pass are:


uwsgi_pass


uwsgi_pass localhost:9000; #normal
uwsgi_pass uwsgi://localhost:9000;
uwsgi_pass suwsgi://[2001:db8::1]:9090; #uwsgi over ssl



If you are using gunicorn to serve your flask app, then your current configs should be fine, check if your app is running and if you can get your index page or not using 5000 port, then check for other problems. your configs looks good, maybe it's a problem on flask not being run?


gunicorn


flask





I've updated my question.
– Abhilash
Aug 31 at 8:42



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)