I’m setting up Nginx as a proxy to apache2 serving a WordPress installation. Issue is that on the root url appsrd.devmbs.com im getting a redirect loop. When I hit the server I see the following in the logs like 12-15 times.
127.0.0.1 - - [03/Sep/2012:12:29:25 +0000] "GET /index.php HTTP/1.0" 301 529 "http://appsrd.devmbs.com/wp-admin/options-general.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_0) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1"
But the /wp-admin works well. No redirect issue. I tried deleting the database, and while the db wasn’t available the root displayed a msg of Error establishing a database connection which is fine since this is the expected behavior but there was no redirect issue. Then I created the DB again and ran the wordpress setup, and when everything is done, the redirect issue comes back.
Beloe my nginx server conf:
server {
listen 80 default_server;
server_name appsrd.devmbs.com;
root /home/ubuntu/projecs/APPS-RD;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /home/ubuntu/projects/APPS-RD;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ .php$ {
proxy_pass http://127.0.0.1:3000;
proxy_buffering on;
proxy_buffers 12 12k;
proxy_set_header Host $host;
}
}
The url is appsrd.devmbs.com, appsrd.devmbs.com/wp-admin works fine.
Anyone have a clue what might be happening?
For any future person that may encounter this problemâ¦
For the purpose of my experiment I wanted Nginx to display any and all existing non-PHP files and to proxy the PHP files and the dynamic URL’s to Apache for WordPress to do its thing. I also wanted WordPress to be able to use the normal .htaccess file.
The problem with the initial code that Luis’ original posted is that Nginx is explicitly declaring the use of index.php because it’s the only index that is given in a WordPress environment. The result is that when you go to “domain.com/” Nginx sends that to Apache looking exactly like “domain.com/index.php”. When WordPress receives “domain.com/index.php” it automatically shortens and redirects you to “domain.com/”; thus you end up with that loop.
The best work around (for the determined) that works for a WordPress environment is to just send any directories to WordPress as well. The downside to this setup is that it will ignore any indexes that aren’t index.php.
If you noticed the contents of the file named *proxy_apache* which is included several times above is,
Again, not necessarily the most practical solution but it does have the advantages of,
I gave up Nginx + Apache when with Nginx + php-fpm
I wanted the same thing Lucas did and I got it to work. Here is a basic example of my congiration.
The key is the if statement inside my @proxy location. I check for a $uri and rewrite the request URI back to / using the break flag. This avoids the redirect loop.
What’s weird is that the problem only occurred on the root index, not on subdirectory indexes. I appreciate any feedback on my configuration. It might have problems I have yet to discover, but as of now it’s providing me with what I need for WordPress deployment.
GL!