admin管理员组

文章数量:1277374

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 :)

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 :)

Share Improve this question edited Jan 26, 2019 at 14:46 butlerblog 5,1013 gold badges26 silver badges43 bronze badges asked Jan 26, 2019 at 8:49 Markus AzerMarkus Azer 1 4
  • What are your SITE and HOME URLs set to? – Richard Smith Commented 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}}; } } ``` – Markus Azer Commented 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. – Richard Smith Commented 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 – Markus Azer Commented Jan 26, 2019 at 11:57
Add a comment  | 

1 Answer 1

Reset to default 1

Just for sharing my experience to others:

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

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

   listen 80;
   server_name domain www.domain;

   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;
   }

}

2- in blog.domain 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";
    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
site Address: http://domain/blog

and you should be good now!

HTTPS version:

1- in server which blog.domain 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;
   }

3- you can do same for domain 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
site Address: https://domain/blog

hope it helps you folks ;)

本文标签: WordPress subdirectory on other server running on nginx