1

I have to applications running using flask and nginx as a reverse proxy. I am having issues serving the static files from my /birthday/ location.

location /{
    proxy_pass http:127.0.0.1:6060;
}

The app that is having issues is.

 location /birthday/
 {
     proxy_pass http:127.0.0.1:6061;
 }

I have tired the following.

 location /birthday/{
   root /var/www/birthday_app/static;
   try_files $uri @bday
 }
 location @bday{
    proxy_pass http:127.0.0.1:6061;
  }

When I serve up http://127.0.0.1/birthday/static/image.png I get status no found. How do I fix the birthday app to serve static files.

1
  • Thanks I added that location ~* /birthday/ {}. But how do I serve the static files? Commented Nov 1, 2019 at 23:52

1 Answer 1

1

So the URI /birthday/static/image.png points to a file at /var/www/birthday_app/static/image.png? You cannot use root on it's own in this situation. You will need to use rewrite...break or alias.

Also, if the URIs beginning with /birthday/static/ serve static files and all other URIs beginning with /birthday/ reverse proxy upstream, you can divide your configuration into two location blocks.

For example:

location /birthday/static/ {
    alias /var/www/birthday_app/static/;
}
location /birthday/ {
    proxy_pass http://127.0.0.1:6061;
}

The value of the location and alias should both end with / or neither end with /. See this document for details.

The URI /birthday/foo will be passed upstream to http://127.0.0.1:6061/birthday/foo without modification. If you need the URI mapped to http://127.0.0.1:6061/foo instead, add a trailing / to the proxy_pass statement. See this document for details.

Sign up to request clarification or add additional context in comments.

3 Comments

I am now really confused. I can access http://127.0.0.1/birthday/static/balloon.jpg That can be accessed from any sub folder in static. http://127.0.0.1/birthday/static/image/balloon.jpg works however '127.0.0.1/birthday/static/image/balloon.css' does not work.
You have a file called balloon.css in the directory at /var/www/birthday_app/static/image/?
OK I think it is working. I believe it was a cached response. After restarting the browser it started working. Thanks for all of the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.