Seb*_*man 31 subdomain rewrite nginx roundtrip
我们的想法是将传入的请求转发http://abc.example.com/...并重写为http://example.com/abc/...
这很容易做到301/302重定向:
# rewrite via 301 Moved Permanently
server {
listen 80;
server_name abc.example.com;
rewrite ^ $scheme://example.com/abc$request_uri permanent;
}
Run Code Online (Sandbox Code Playgroud)
关键是要做到这一点URL变化透明的客户端时abc.example.com,并example.com点于同一Nginx的实例.
换句话说,Nginx可以在请求example.com/abc/...时提供内容,abc.example.com/...而无需另外客户往返吗?
起点配置
使用301完成任务的Nginx配置:
# abc.example.com
server {
listen 80;
server_name abc.example.com;
rewrite ^ $scheme://example.com/abc$request_uri permanent;
}
# example.com
server {
listen 80;
server_name example.com;
location / {
# ...
}
}
Run Code Online (Sandbox Code Playgroud)
小智 37
# abc.example.com
server {
listen 80;
server_name abc.example.com;
location / {
proxy_pass http://127.0.0.1/abc$request_uri;
proxy_set_header Host example.com;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12898 次 |
| 最近记录: |