Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Re: Nginx rewrite not working as expected

$
0
0
It's a bit hard to understand what you are really trying to do. I am guessing it may be something along the lines of this:

map $realURI $handler {
"~*/sess.*[.]php$" "_php";
"~*/sess.*[.](jpg,gif,png,svg)$" "_images";
"~*/sess.*$" "_static";
default "_session";
}

location ~ "^/(?<sessionID>sess[a-z0-9]+)(?<realURI>.*)$" {
rewrite "^.*$" "/$handler/$realURI";
}

location /_php {
internal;
# do your fastcgi stuff
}

location /_images {
internal;
# deliver from your image repository
}

location /_static {
internal;
# deliver your static content
}

location /_session {
internal;
# create a session and redirect further, e.g., via js_content
}

The idea is to have a classification of the URI with the map directive. Then you do internal redirects to the actual (internal) location handling the case properly. This way, you may set entirely different headers, proxy parameters, etc. for each handler. You may even handle cases without the session id by directing such requests to a location with a Javascript handler, that creates a session according to custom logic and then redirects to the proper location handling the content.

--j.

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>