0

I have main site running on node on instance and I used sub-directory to run WordPress on another instance nginx config

location /eg-en/blog {
        proxy_pass http://{{Instance-Ip}};
    }

The issue is the when I open inspect I see that the resources (Network Tab) is coming from WordPress instance IP!!

My question here how to clean Network tab and make it show it's loading from main website?!

Thanks, if there is any further explanation, please just ask :)

4
  • What are your SITE and HOME URLs set to? Jan 26, 2019 at 10:07
  • Here is the full block ``` server{ listen 80; expires $expires; server_name {{SitName}}; location / { auth_basic off; proxy_pass 127.0.0.1:3100; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } location /eg-en/blog { proxy_pass {{Instance-Ip}}; } } ``` Jan 26, 2019 at 10:22
  • You should edit the question to add formatted text - and my last comment related to the WordPress control panel. Jan 26, 2019 at 10:41
  • Sorry for late response, i accidentally changed WordPress Address (URL) and took me sometime to figure out that i can change it throw wp-cli well WordPress Address (URL) points to instance IP Site Address (URL) Points to {{website Url}}/blog Jan 26, 2019 at 11:57

1 Answer 1

1

Just for sharing my experience to others:

I have main site with domian.com and want to subdirectory domain.com/blog reverse proxy to blog.domain.com which is a wordpress with nginx! so this is how things work for me:

HTTP version:
1- in domian.com nginx config set /blog like this:

   listen 80;
   server_name domain.com www.domain.com;

   location / {

      root /path/file/content;
      index index.php index.html;


   }

   location /blog/ {
        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  $scheme;
        proxy_pass http://blog.domain.com;
   }

}

2- in blog.domain.com setup normal nginx config and just add CORS in server block for loading fonts and other stuff:

    add_header 'Access-Control-Allow-Origin' "http://domain.com";
    add_header 'Access-Control-Allow-Methods' 'GET, POST';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Headers' 'User-Agent,Keep-Alive,Content-Type';
    add_header 'Referrer-Policy' 'origin';

3- go to admin panel in wordpress then in settings and change your parameters like:

wordpress Address: http://blog.domain.com
site Address: http://domain.com/blog

and you should be good now!

HTTPS version:

1- in server which blog.domain.com wordpress exist do certbot --nginx and make it https

2- next change domain's nginx conf file like this:

   location /blog/ {
        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  $scheme;
        proxy_pass https://blog.domain.com;
   }

3- you can do same for domain.com but I used CDN for make it https

4- go to admin panel in wordpress then in settings and change your parameters like:

wordpress Address: https://blog.domain.com
site Address: https://domain.com/blog

hope it helps you folks ;)

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.