Nginx - 在不同服务器的子目录中运行网站

Nginx - 在不同服务器的子目录中运行网站

我有一个网站https://www.winni.in在 nginx 后面的 tomcat 中运行,我在 wordpress 中也有一个博客,它的网址为https://www.winni.in/blog这两个都位于 aws ec2 中的同一台机器上

由于某些原因,我希望将 wordpress 博客放在也运行 nginx 的单独 ec2 实例上。但我不想将 url 更改为 blog.winni.in 之类的子域名,有什么方法可以做到这一点?通过这种方式,我可以在单独的 ec2 实例上运行博客,但继续使用 url 作为winni.in/blog

答案1

您可以在 Nginx 中使用代理:

location / {
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   Host      $http_host;
    proxy_pass         http://YOURTOMCATSERVER:{PORT};
}

location /blog {
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   Host      $http_host;
    proxy_pass         http://YOURBLOGSERVER:{PORT};
}

答案2

您可以考虑使用 Nginx 作为 Tomcat 和 wordpress 的反向代理。

为 /blog/ 添加单独的位置标签,并将该流量代理传递到新的 wordpress ec2 服务器。这将确保您的 URL 保持在http://winni.in/blog/& 在 wordpress 中配置 siteurl 为http://winni.in你的 nginx 服务器的 hosts 文件需要进行以下输入

newEC2IP地址 winni.in

相关内容