我正在尝试将请求从子域重写到子文件夹,因此URL在浏览器中保持为subdomain.example.com
,但显示example.com/subdomain
的内容。
我尝试过使用rewrite指令,但这会重定向用户,而不是更改浏览器中的URL。如何在不更改浏览器中的URL的情况下执行此操作?
下面是我尝试过的代码:
server {
server_name subdomain.example.com;
location / {
rewrite ^/(.*)$ https://example.com/subdomain/$1 permanent;
}
}
server {
listen 80;
server_name subdomain.example.com;
location / {
rewrite ^ /subdomain$request_uri last;
}
}
有人能帮我吗?
1条答案
按热度按时间7ajki6be1#
你可以在Nginx中使用
proxy_pass
指令来实现这一点。以下是修改配置的方法: