amuck-landowner

nginx - File by file redirection with reverse proxy

drmike

100% Tier-1 Gogent
Working on updating an old project and have random problem getting something working in nginx.

Trying to do something like this:

existing url:  www.domain.com/page.asp ---> redirect "invisibly" to user to new url: www.domain.com/page.php (via nginx reverse proxy)

I basically have a list of URLs that are getting one at a time replaced / rewrote (pages contain backend application scripting that is getting rewrote).  So can't just do detect on the extension (.asp) and universally reverse proxy them.

Anyone have some nginx love / config / tips on how to accomplish this?

I also don't want the URLs changing since other pieces in public out there.  URL provided by user needs to remain the same and all the magic needs to happen with Nginx and reverse proxy functionality.

Thank you!
 

Munzy

Active Member
is the file name the same?

i.e. page1.asp = page1.php?

If so.... You could always make nginx run the php fastcgi for .asp files.... 

I think
 

drmike

100% Tier-1 Gogent
is the file name the same?

i.e. page1.asp = page1.php?

If so.... You could always make nginx run the php fastcgi for .asp files.... 

I think
Yeah, problem is some of the ASP files are still going to live in ASP land for now (pending re-write)....

New ones get one off upgraded, tested and deployed as PHP version.

But literally for the updated files:

page1.asp = page1.php
 

drmike

100% Tier-1 Gogent
location /oldurl.asp {

    proxy_pass http://server/newurl.php;

}

Would this work or am I missing something
While my config accepts this and nginx restarts just fine, it fails to work. 

Are you using something similar with the /newurl.php part or similar defined in a config of your own?   I've never dealt with proxy_pass with the the filename part prior....  Having issues finding good examples elsewhere also....
 

JahAGR

New Member
While my config accepts this and nginx restarts just fine, it fails to work. 

Are you using something similar with the /newurl.php part or similar defined in a config of your own?   I've never dealt with proxy_pass with the the filename part prior....  Having issues finding good examples elsewhere also....
Yes. In my case I'm using this nginx install in front of a remote Apache that does all the work.

The config for my site is more or less as follows... 


server {
#listen stuff
#server_name blah;
#logging stuff

location /specific.php{
proxy_pass http://backend/some_dir/script.php;
}
location /{
proxy_pass http://backend/other_dir/;
}
}


The only other relevant config change I made was "proxy_redirect off;" in the http block of the main nginx.conf

I guess make sure that reverse proxying is working at all, and then just add additional "location" blocks
 
Last edited by a moderator:

zzrok

New Member
You should make sure you don't have a less specific location that matches earlier in the config.  You could also try converting your location to an exact match, like below, since that has higher priority.

Code:
location = /oldurl.asp {
 
Top
amuck-landowner