I’m trying to use nginx as a proxy to wordpress but I’m getting weird behavior.
There is my nginx configuration:
location ~ ^/blog(/?)(.*) {
proxy_pass http://<ip addr>/$2$is_args$args;
proxy_redirect off;
}
When I access www.hostname.com/blog/, I receive a redirect (301) to <ip addr>/blog/.
I checked the apache’s access.log and there is no record of the redirects, what makes me believe that is nginx that is doing that.
Any idea of what could be causing this?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Try this instead:
location /blog {
rewrite ^/blog/(.*)$ /$1 break;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_pass http://127.0.0.1:8080$is_args$args;
proxy_redirect off;
}
Does that work? (make sure you replace 8080 with the port apache is listening on)
Thanks for your reply.
I tried this configuration and now when I request /blog it works ok, but when I request /blog/anything the response is a redirect to root:
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Mon, 11 Aug 2014 16:27:16 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 0
Connection: keep-alive
X-Powered-By: PHP/5.5.9-1ubuntu4
X-Pingback: http://104.131.199.80/xmlrpc.php
Location: http://www.insectashoes.com/
proxy_pass http://backend/$request_uri;
this does the trick for most scenarios as it matches the url that was requested. However, redirects don’t seem to work when using the proxy. Still scouring the interwebs for an answer
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.