2ircdq
Last Updated: March 24, 2016
·
1.238K
· tmartin314

Wordpress Blog behind Rails app using Nginx reverse proxy

Set blog up on subdomain

blog.domain.com

Set WP constants in wp-config.php

$_SERVER['HTTPS'] = 'on';
define('WP_HOME', "https://www.domain.com/blog");
define('WP_SITEURL', "https://www.domain.com/blog");

Configure Nginx proxy pass

location /blog {
  proxy_pass http://blog.domain.com;
  proxy_http_version                  1.1;
  proxy_set_header  Connection        "";
  proxy_set_header  Host              $host;
  proxy_set_header  X-Forwarded-For   $proxy_add_x_forwarded_for;
  proxy_set_header  X-Real-IP         $remote_addr;
}

An alternative setup:

location /blog {
  proxy_set_header  X-Real-IP  $remote_addr;
  proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
  #proxy_set_header Host $http_host;
  proxy_redirect false;

  if (!-f $request_filename) {
    rewrite ^/blog$     /;
    rewrite ^/blog/(.*)$ /$1;
    proxy_pass http://blog.domain.com;
    break;
  }
}