I have an nginx server processing PHP requests, but it's configured to listen on a non-standard port (port 12345 or something). I can't change the listen port because corporate IT says, "No."
There is a proxy in the data center that forwards requests from www.domain.com:80 to the nginx box on port 12345.
I have some static 301 redirects that I need to put in place, but I'm getting unexpected behavior.
Sample redirects in site.conf "server { }" block:
rewrite ^/foo$ /bar/foo/ permanent;
When I attempt to go to www.domain.com/foo, the redirect happens, but it tries to forward the browser to www.domain.com:12345/bar/foo/
My question is, how can I get nginx to redirect the user to the correct port (www.domain.com/bar/foo/)?
Maybe a better question is, what is the correct way to do what I'm asking? There are 50+ redirects that need to go in, and I'd rather not create a "location" section for each of those redirects.
Temporary and Permanent Nginx Redirect Explained On the other hand, a permanent Nginx redirect informs the web browser that it should permanently link the old page or domain to a new location or domain. To map this change, the redirects response code 301 is used for designating the permanent movement of a page.
The reasons for 301 redirect not working are much more well-defined among WordPress sites. One of the main causes is because you have added the rewrite rules on both the cPanel “Redirects” tool and from your WordPress plugin.
You can provide a more explicit rewrite. Try the following:
rewrite ^/foo/ $scheme://www.domain.com:80/bar$request_uri permanent;
I have assumed that you meant to use ^/foo/
instead of ^/foo$
, since ^/foo$
is a very specific case. Just revise as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With