Redirect to 127.0.0.1 when access a wordpress hosted with apache and nginx in proxy

I have a wordpress hosted on Apache2 with Nginx in front of.
<WORLD> ===> <NGINX PROXY> --> APACHE/DOCKER/STATIC WEBSITE etc...

My nginx conf for wordpress proxy is :

Read More
server {
    server_name dev-www.example.com;

    location / {
        proxy_pass http://127.0.0.1:13400;
    }
}

My apache configuration :

Listen 13400

<VirtualHost 127.0.0.1:13400>
        CustomLog /var/log/httpd/sites/dev-www/access_log combined
        ErrorLog /var/log/httpd/sites/dev-www/error_log

        DirectoryIndex index.php

        DocumentRoot /var/www/sites/example.com/dev-www

        RewriteEngine On

        <Directory /var/www/sites/example.com/dev-www/>
                Options Indexes FollowSymLinks
                AllowOverride all
        </Directory>

</VirtualHost>

And wordpress .htaccess :

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>

# END WordPress

The issue is when I go on dev-www.example.com/foobar.php I am redirected to 127.0.0.1/foobar.php. I know it’s from nginx configuration 127.0.0.1 pop out put how to fix it ?

I try to proxy pass to dev-www.example.com:13400 but I got an infinite loop :

[Tue May 10 23:44:45.001680 2016] [core:error] [pid 1096] [client
127.0.0.1:54887] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use
‘LimitInternalRecursion’ to increase the limit if necessary. Use
‘LogLevel debug’ to get a backtrace., referer:
http://dev-www.example.com/

note: there is no problem with http://dev-www.example.com or http://dev-www.example.com/index.php
Thanks.

note2 : If I change nginx configuration to localhost:13400, then i’m redirected to localhost/login-3. It looks like .htaccess redirect to ServName and it is 127.0.0.1

Related posts

3 comments

  1. It’s wordpress redirect to HTTP_HOST, adding

    $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
    

    in wp-config.php fix it.

  2. It sounds as you had exported your wordpress site from a local development system to productive system. Very likely you can not get into /wp-admin anymore as well. In this case you have to manually update the database entries in the table wp_options. Look for the options siteurl and home.


    Please also try out to add this to wp-config.php (but i’m afraid, this is only targeted to outgoing requests)

    define('WP_PROXY_HOST', '1.2.3.4');
    define('WP_PROXY_PORT', '13400');
    # define('WP_PROXY_USERNAME', 'my_user_name');
    # define('WP_PROXY_PASSWORD', 'my_password');
    define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com');
    
  3. For Nginx, you have to make sure Host header is set correctly, your example should be:

    server {
        server_name dev-www.example.com;
    
        location / {
            proxy_set_header Host dev-www.example.com;
            proxy_pass http://127.0.0.1:13400;
        }
    }
    

Comments are closed.