Skip to content

Instantly share code, notes, and snippets.

@amanjuman
Last active June 2, 2022 21:35
Show Gist options
  • Save amanjuman/7b6cd1e37ac92c9043e74c863ebd0f13 to your computer and use it in GitHub Desktop.
Save amanjuman/7b6cd1e37ac92c9043e74c863ebd0f13 to your computer and use it in GitHub Desktop.
Wordpress Blog as a sub-folder of domain using nginx reverse proxy

Add in WordPress Config File after "define( 'DB_COLLATE', '' );"

define('WP_SITEURL', '/blog');
define('WP_HOME', '/blog');
$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/",  $_SERVER['REQUEST_URI']);

Add this after above line if your WordPress Blog is Non-SSL

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
    $_SERVER['HTTPS']='on';

Nginx Configuration (Main Domain Configuration)

location /blog/
{
		rewrite ^([^.]*[^/])$ $1/ permanent;
		rewrite ^/blog/(.*)$ /$1 break;

		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $remote_addr;
		proxy_set_header Host blog.domain.tld;
		
		proxy_set_header X-Forwarded-Proto $scheme;
		proxy_pass https://SERVER-IP;
		proxy_redirect off;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment