2

I have a flaskapp, deployed using nginx as proxy server and gunicorn. I have several routes defined in the Flask python script, except they aren't accessible.

When using development server, however, they work just fine.

All routes except the base url ("/") return 404 nginx page, so I'm assuming there's something with nginx, but I found nothing that could help me with it.

How to configure nginx to accept these routes and use the one defined in flaskApp?

RishbhSharma
  • 365
  • 3
  • 9

1 Answers1

1

That's because you did not define all the routes in your nginx configuration, you should have something like the example below, except that you should change server_name and ports.

Note : I was using this snippet to connect nginx to other containers so think about changing http://client:80; to your localhost or application name, also do the same for all the routes.

The main idea is to define all routes.

http {
     server {

        listen 80;
        server_name localhost 127.0.0.1;

        location / {
            proxy_pass          http://client:80;
            proxy_set_header    X-Forwarded-For $remote_addr;
        }

        location /api/ {
                # why should i add / at the end 5000/ to make it work 
            proxy_pass          http://api:5000/;
            proxy_set_header    X-Forwarded-For $remote_addr;
        }

        location /api/client {
            proxy_pass          http://api:5000/client;
            proxy_set_header    X-Forwarded-For $remote_addr;
        }

}

Kevin Bowen
  • 20,055
  • 57
  • 82
  • 84