010*_*101 6 nginx url-rewriting
我有两个不同的网络应用程序.它们被设置在根目录的不同服务器上.但现在它们将被放置在同一服务器上的子目录中.下面的脚本将子目录和URI一起发送到脚本.这是个问题.
旧网址:
新网址:
商店网站看到/store/items/1它想要看到的时间/items/1.后台网站也是如此.
我的尝试:
location /store {
try_files @store_site;
}
location /backoffice {
try_files @backoffice_site;
}
location @store_site {
include uwsgi_params;
uwsgi_pass unix:/var/run/uwsgi/store_site.sock;
proxy_set_header Host $host;
}
location @backoffice_site {
include uwsgi_params;
uwsgi_pass unix:/var/run/uwsgi/backoffice_site.sock;
proxy_set_header Host $host;
}
Run Code Online (Sandbox Code Playgroud)
同样,商店网站正在获取带有/store前缀和后台的URL /backoffice.这些网站被编码为不期望这些前缀.我需要在发送到实际站点之前删除/store和/backoffice前缀.
这是重写规则吗?
我基于这个SO页面尝试了这个,但它没有用.我不能理解语法.
location /store {
rewrite ^/store/(.*) /$1;
try_files $uri @store_site;
}
Run Code Online (Sandbox Code Playgroud)
更新
显然,这是有效的(补充break;)这是一个完整的解决方案吗?
location /store {
rewrite ^/store/(.*) /$1 break;
try_files $uri @store_site;
}
Run Code Online (Sandbox Code Playgroud)
Day*_*ayo 13
您需要重写uri而不会触发重定向,如使用中所述break.
根据您设置的详细信息,是否所有内容都应该发送到后端,或者Nginx是否应该提供某些请求(如静态文件),您需要...
location /store {
try_files $uri @store_site;
}
location /backoffice {
try_files $uri @backoffice_site;
}
location @store_site {
rewrite ^/store/(.*) /$1 break;
include uwsgi_params;
uwsgi_pass unix:/var/run/uwsgi/store_site.sock;
}
location @backoffice_site {
rewrite ^/backoffice/(.*) /$1 break;
include uwsgi_params;
uwsgi_pass unix:/var/run/uwsgi/backoffice_site.sock;
}
Run Code Online (Sandbox Code Playgroud)
... 要么
location /store {
rewrite ^/store/(.*) /$1 break;
include uwsgi_params;
uwsgi_pass unix:/var/run/uwsgi/store_site.sock;
}
location /backoffice {
rewrite ^/backoffice/(.*) /$1 break;
include uwsgi_params;
uwsgi_pass unix:/var/run/uwsgi/backoffice_site.sock;
}
Run Code Online (Sandbox Code Playgroud)
我建议你试试这个:
location /store/ {
rewrite ^/store/(.*) /$1 break;
include uwsgi_params;
proxy_set_header Host $host;
uwsgi_pass unix:/var/run/uwsgi/store_site.sock;
}
Run Code Online (Sandbox Code Playgroud)
还没有测试过,但我认为它应该可以工作。
| 归档时间: |
|
| 查看次数: |
11500 次 |
| 最近记录: |