Question

NGINX Reverse Proxy configuration for WordPress running on apache with http

Posted January 2, 2018 6.7k views
CentOSWordPress

Hi, I have tried with the above configuration in my environment with plain http connection for apache/wordpress, it is not working for me. My configuration details are as below.
nginx:

 proxy_pass http://upstream/$request_uri;
 proxy_set_header X-Forwarded-Host $host;
 proxy_set_header X-Forwarded-Proto $scheme;

apache .htaccess:

# BEGIN WordPress

RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

wp-config.php:
if ( (!empty( $_SERVER[‘HTTP_X_FORWARDED_HOST’])) || (!empty( $_SERVER[‘HTTP_X_FORWARDED_FOR’])) ) {
$_SERVER[‘HTTPS’] = ‘on’;
}

When I am hitting nginx URL, apache/WordPress port is appearing in the browser URL as https://host-one:8080/blog/ instead https://host-one:9443/blog (My Nginx https port is 9443). Can you please advise, what is missing in my configuration. Thanks.

edited by asb

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hello,

I think that you need to adjust your ports in your proxy pass. I would usually use something like this:

  location / {
    proxy_pass http://127.0.0.1:PORT; # change the port here
    proxy_buffering on;
    proxy_buffers 12 12k;
    proxy_redirect off;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr;
    proxy_set_header Host $host;
  }

Regards,
Bobby

Submit an Answer