Fix wordpress 301 loop when enable nginx…

I am try to setup Nginx as reverse proxy, backend is Apache, the problem is WordPress always 301 to the same URL even if the browser request that URL (301 loop).


client <---> nginx(https) <---> apache(http)

The problem is WordPress think the site is on port 80 enable https, but actually apache is on 8080 without https, and Nginx is on 80 with https, so it request 301 to that ‘correct’ site… See below.

After digging Google for a long time, and found some solutions at the end.

this is my solution temporary. Just comment out canonical, because I don’t need it.

update:

After trace Nginx and Apache traffic, I found that Nginx always add ‘index.php’ to ‘/’, then send to apache, but wordpress will make 301 redirect to ‘/’, so browser request ‘/’ again, when Nginx received, it add ‘index.php’ to it and send to apache again, loop…

the solution is:

And append this to wp-config.php

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

This entry was posted in Memo and tagged , , , . Bookmark the permalink.