Nginx Docker flask
How to deploy the flask app in HTTPS without changing the port.
Right now I have assigned port for ngnix (with ssl) 5001, flask is deployed to the port 5000. How to use the same port for HTTPS (port 5000).
I'm using ngnix as a docker image.
I'm new to this service. Any help would suffice.
Posted Oct 13, 2020, 9:11 AM UTC
15
Is flask listening on port 5000 directly, or is nginx listening on port 5000 and passing it onto flask?
You can't have two apps listening on the same port. And you can't have http and https traffic on the same port even with same application (maybe funny workaround, where you can redirect http to another protocol/port).
These are you main limitations, so if flask is listening forr http on port 5000, nginx can't listen for https on that port. And if you're using port 5000 for http on nginx, you can't use it for https in nginx.
Does that make sense? Best option would be different ports. Best case might be using dns and default ports to make seperate services.
Got it ☹.
Flask is running in 5000 Without SSL context and routed to nginx with certificates to port 5001.
I'd maybe recommend using nginx to proxy traffic to flask.
Are you running any other services in nginx? Do the requests to flask include a host header?
I have other micro services with different ports but those dont have relation with nginx. The port that is deployed is only one 5000 hence it is the one I need to redirect.
Is there a way if I use, let's say http://localhost:5000. Can it redirect to https://localhost:5000.
You can't have seperate protocols with same ip, hostname and port.
You can do redirects with the workaround i mentioned, but that wouldnt be telling the client to switch to https. And you wouldn't have a http service.
You have options it depends what you want the behaviour to be.