PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 1, 2022

[FIXED] Why isn't proxy_pass in Nginx handling sub uris?

 September 01, 2022     nginx, nginx-config, nginx-reverse-proxy     No comments   

Issue

I'm trying to proxy a sub path in my web app to an asset server (to avoid cross domain issues).

I've added this configuration to the server context in nginx.conf.

location /assets2/ {
    proxy_pass http://itype-assets/videos/transparent/classroom.png;
}

location /assets/ {
    proxy_pass http://itype-assets/;
}

After adding this config I'm finding that:

http://localhost:8080/assets2/ - serves up the expected image

http://localhost:8080/assets/videos/transparent/classroom.png - returns 404

What am I missing here?

Edit :

On further investigation I've discovered that removing a subsequent rule resolves the issue:

    location ~ ^.+\..+$ {
        try_files $uri =404;
    }

However, I need that rule to serve my static files. Changing the order the rules are declared in doesn't alter the behaviour.

So my question becomes, how can I use my proxy_pass rule alongside my try_files rule?


Solution

It turns out nginx will always resolve regex location matches over prefix location matches.

This behaviour can be overridden by modifying my location declaration to:

location ^~ /assets/ {
    proxy_pass http://itype-assets/;
}


Answered By - Programming Guy
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing