Forwarding Nginx port to gunicorn instance

Luis Liz

I was following this tutorial to setup my flask server.

https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04#step-6-%E2%80%94-securing-the-application

When I got to step 6 I see that they are setting flask for the whole url but I would like to point it to a specific port.

This is the code I have for my nginx which points. This currenly produces a 404.

server {
        listen 5000;
        server_name site.com;

        location / {
                include proxy_params;
                proxy_pass http://unix:/home/user/project/project.sock;
        }
}

All the other files are the same as the tutorial. I have tried to modify the .sock file but it seems like it was generated automatically and it can't be modified. In addition I need to find a way for nginx to handle this before I worry about handling it from gunicorn.

My end goal is to have nginx foward requests to flask running when a request is sent to 0.0.0.0:5000 and have all other requests 0.0.0.0 , 0.0.0.0/* be handled by nginx.

Any help to undestand all this is really appreciated got lost at this point.

EDIT

my nginx configuration in sites-available

server {
     server_name domain www.domain; 
     location / {
         include proxy_params; 
         proxy_pass http://127.0.0.1:8080/; 
     }
}
edilio

If you want flask to be open to a port instead of a file you should override [service] to

[service]
...
ExecStart=/home/sammy/myproject/myprojectenv/bin/gunicorn --workers 3 --bind 127.0.0.1:8000 -m 007 wsgi:app

And change your nginx config to proxy_pass http://127.0.0.1:8000/;

This way you can have access to port 8000 for checking how are working gunicorn and flask. Remember to be careful with firewall rules to secure port 8000. For a good discussion on which one is better you can try: gunicorn + nginx: Server via socket or proxy?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Forwarding Multiple port to Single port using nginx

nginx & docker - Forwarding port 80/443 to 3000

Nginx Reverse Proxy with Port Forwarding Not Working

Flask, Nginx, Gunicorn Stack Launching Selenium instance

Restricting direct access to port, but allow port forwarding in Nginx

Gunicorn, nginx, django, inside of a docker container. Gunicorn successfully runs on port 80 but nginx fails

Port forwarding on AWS from the internet to private subnet instance

How can I apply port forwarding to an Azure Container Instance?

Port Forwarding

Port forwarding

Forwarding port to Node.js app with Nginx and routing

nginx port forwarding to port 80 from a running meteor app at port 3001

Port forwarding error: Port forwarding is not forwarding to server

Configuring Gunicorn with nginx - nginx displaying 500 Internal Server Error when running on port 8000

Port forwarding not working for port 9

UDP Port Forwarding and outgoing port

Persistent disk missing when I SSH into GCP VM instance with Jupyter port forwarding

ssh tunneling/port forwarding not working through EC2 instance to an Elasticsearch cluster in a VPC

access EC2 Ubuntu instance's localhost address from local web browser using port forwarding

Troubleshooting port forwarding

Port Forwarding Rule Semantics

SSH tunnel Port forwarding

DVR & Port Forwarding

iptables and router port forwarding

Port forwarding to local server

Docker not port forwarding correctly?

VirtualBox port forwarding with Packer

port forwarding service -> container

Python port forwarding