3

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 :

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

8
  • "when I go on dev-www.example.com/foobar.php I am redirected" means when you enter this URL directly into the browser's location bar? May 10, 2016 at 23:14
  • Yes, or click on link, same behavior. dev-www.example.com/login-3 redirect me to 127.0.0.1/login-3 May 11, 2016 at 7:57
  • 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 May 11, 2016 at 7:59
  • Have you tried curl -D - dev-www.example.com on the command line? May 11, 2016 at 8:38
  • 1
    There's no redirect in your .htaccess. Wordpress must be doing that. May 11, 2016 at 8:59

3 Answers 3

18

It's wordpress redirect to HTTP_HOST, adding

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

in wp-config.php fix it.

2
  • Thanks! My final solution to leave Wordpress config file unchanged was to add ProxyPreserveHost On to the proxy instance (on apache).
    – Wadih M.
    Sep 3, 2019 at 20:12
  • For nginx you have to add proxy_set_header Host domain.com
    – ahmed
    Oct 7, 2020 at 23:47
1

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
  • I already change it. Nothing change (but I can access to dev-www.example.com or /index.php) without any issue. May 10, 2016 at 22:24
  • @CyrilALFARO What are those options set to? May 10, 2016 at 22:34
  • there was an error on my post at apache conf, I fill IP and not URL, I just update my post. May 10, 2016 at 22:51
1

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;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.