Created
October 25, 2016 08:17
-
-
Save v-thomp4/e190c50262ecd048f351d9e64f6ffd68 to your computer and use it in GitHub Desktop.
wordpress https nginx proxy_pass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wp-config.php | |
``` | |
// If WordPress is behind reverse proxy | |
// which proxies https to http | |
if ( (!empty( $_SERVER['HTTP_X_FORWARDED_HOST'])) || | |
(!empty( $_SERVER['HTTP_X_FORWARDED_FOR'])) ) { | |
// http://wordpress.org/support/topic/wordpress-behind-reverse-proxy-1 | |
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; | |
define('WP_HOME', 'https://mysite.com/blog'); | |
define('WP_SITEURL', 'https://mysite.com/blog'); | |
// http://wordpress.org/support/topic/compatibility-with-wordpress-behind-a-reverse-proxy | |
$_SERVER['HTTPS'] = 'on'; | |
} | |
``` | |
.htaccess | |
``` | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteRule ^index\.php$ - [L] | |
RewriteRule (.+)/$ http://mysite.com/blog/$1 [R=301,L] | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteCond %{REQUEST_FILENAME} !-d | |
RewriteRule . /index.php [L] | |
</IfModule> | |
``` | |
nginx.conf | |
``` | |
location ^~ /blog/ { | |
proxy_pass http://172.16.8.63:8080/; | |
proxy_set_header Host $host; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Forwarded-Proto http; | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment