我有一个为生产网站https://example.com
提供服务的rails应用。我还在https://blog.example.com
的同一个网站上有一个WordPress博客。出于维护和营销原因,我们希望在主网站中不断更改网址,例如/about
,/faq
等,以便使用WordPress管理,但在主网站下提供,以便 - < / p>
https://example.com/about
将呈现https://blog.example.com/about
但不会重定向,与https://example.com/faq
相同,就好像它们已安装在该主域下一样。
https://example.com/anything-else
将使用rails后端等
显然,这可以通过简单的重定向来实现,但我希望保留相同的网址 - 这可能吗?我尝试使用proxy_pass
,但最终获得重定向到新网址:
server {
# WordPress configuration
listen 443 ssl;
server_name blog.example.com;
root /var/www/blog;
#...
}
server {
listen 443 ssl default;
# .. misc SSL settings
server_name example.com www.example.com;
root /var/www/example;
# .. misc settings
location /about {
# ... render blog.example.com/about
}
location /faq {
# ... render blog.example.com/faq
}
location @unicorn {
# ... unicorn configuration
}
}
感谢。
答案 0 :(得分:1)
关键是你会告诉nginx将某些请求代理到另一台服务器(在这种情况下是wordpress)
sever {
#this is the rails server
# These are all the locations combined into one condition
# or you can split them to different locations if u want
location /(faq|about|whatever) {
# asking nginx to proxy these requests to this URL
proxy_pass http://blog.example.com;
}
# The remaining cases that don't match the above criteria,
# in your case this is where you want to pass to rails.
location / {
# remaining of rails settings
}
}