Nginx proxy for apache2 guide, mod_rewrite not working

June 21, 2013 4.2k views
The guide followed was here: https://www.digitalocean.com/community/articles/how-to-configure-nginx-as-a-front-end-proxy-for-apache I've setup everything and modified some other stuff to my liking, however as stated by another user, a fresh Wordpress install gives a redirect loop error on the index page. The dashboard works fine. To get around that error, I had to add remove_filter('template_redirect', 'redirect_canonical'); to the theme's functions.php file. Now I try to enable friendly urls with the .htaccess and it doesn;t work, it just reloads the same page no matter what I click. Is there something I'm missing? My Nginx server block: https://paste8.com/KPMSQwXN My Apache vhost: https://paste8.com/q6BwHube Any help is appreciated.
2 Answers
Fixed the issue myself.

New Nginx config: https://paste8.com/AetMDiCe

Your try_files changes the URL to /index.php in order to send it upstream which looses the pretty permalink.

You might try to send the pretty permalink upstream by adding a named location. Maybe:

location / {
try_files $uri $uri/ @proxy;
}

location @proxy {
proxysetheader X-Real-IP $remoteaddr;
proxy
setheader X-Forwarded-For $remoteaddr;
proxysetheader Host $host;
proxypass http://127.0.0.1:8080;
}
location ~ .php$ {
proxy
setheader X-Real-IP $remoteaddr;
proxysetheader X-Forwarded-For $remoteaddr;
proxy
setheader Host $host;
proxy
pass http://127.0.0.1:8080;
}

font https://serverfault.com/questions/755759/mod-rewrite-issue-apache-behind-nginx

Have another answer? Share your knowledge.