Mojimi
Mojimi

Reputation: 3151

Flask with NGINX proxy_pass

I have a python flask server running on localhost:5000

I want NGINX to forward www.example.com/app/rest to localhost:5000/rest

Problem is, flask's url_for links will bypass any configuration, for example, I may have this button :

<a href="/rest">Rest</a>

Which will them route the browser to www.example.com/rest, which maps to nothing.

How can I fix this? From my understanding just changing nxing conf isn't enough, I also need to change something in Flask

My NGINX conf is as follows :

location /deploy/ {

      proxy_pass http://localhost:5000/;
      proxy_set_header Host $host;

}

Upvotes: 1

Views: 5908

Answers (1)

J-Jacques M
J-Jacques M

Reputation: 1118

Try this

location /app/rest/ { # the trailing slash at the end is important

      proxy_pass http://localhost:5000/rest;
      proxy_set_header Host $host;

}

location /deploy/ {

      proxy_pass http://localhost:5000/;
      proxy_set_header Host $host;

}
...
location / { # always be placed at the end
      ...
}

Upvotes: 1

Related Questions