我的设置如下:
example.com/de现在是example.de,example.com/en现在是example.com.我正在使用nginx最新版本.
我需要保留通过iOS应用程序发送到http://www.example.com/de/api/uploadPicture的帖子,现在是http://www.example.com/api/uploadPicture.
我发现我需要使用位置而不是重写规则.
这就是我在.com块中的内容:
location /de/shop {
rewrite ^/de/shop/(.*) http://www.example.de/$1 redirect;
}
location /de {
rewrite ^/de/(.*) http://www.example.de/$1 redirect;
}
location /en/shop {
rewrite ^/en/shop/(.*) http://www.example.com/$1 redirect;
}
location /en {
rewrite ^/en/(.*) http://www.example.com/$1 redirect;
}
Run Code Online (Sandbox Code Playgroud)
这是上面提到的部分:
location /de/api/uploadPicture {
# Not sure how to use this one
#proxy_pass http://myproject$uri$is_args$args;
#proxy_redirect http://localhost:8080//;
# This works, but looses the post data
rewrite ^/de/api/(.*) http://www.example.com/api/$1 redirect;
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
编辑:我已经调整了给定的解决方案.这有效,但不能与重写规则结合使用:
server {
client_max_body_size 20M;
listen 80;
listen 443 ssl;
ssl_certificate /home/ib/ssl/ib.pem;
ssl_certificate_key /home/ib/ssl/ib.key;
server_name www.example.com;
location / {
proxy_pass http://myproject;
error_page 500 502 503 504 /error.html;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-REAL-SCHEME $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /error.html {
root /home/ib/error;
}
location ~ ^/de/api/(?<method>.*)$ {
if ($request_method = POST) {
return 307 http://www.example.de/api/$method$is_args$args;
}
# non-POST requests
rewrite ^/de/api/(.*) http://www.example.com/api/$1 redirect;
}
location ~ ^/en/api/(?<method>.*)$ {
if ($request_method = POST) {
return 307 http://www.example.com/api/$method$is_args$args;
}
# non-POST requests
rewrite ^/de/api/(.*) http://www.example.com/api/$1 redirect;
}
rewrite ^/de/shop/(\d+)/(.*) http://www.example.de/$1/$2 permanent;
rewrite ^/en/shop/(\d+)/(.*) http://www.example.com/$1/$2 permanent;
rewrite ^/de/(.*)-(\d+) http://www.example.de/$1-$2.html permanent;
rewrite ^/en/(.*)-(\d+) http://www.example.com/$1-$2.html permanent;
rewrite ^/de/shop/(.*)-(\d+) http://www.example.de/$1-$2.html permanent;
rewrite ^/en/shop/(.*)-(\d+) http://www.example.com/$1-$2.html permanent;
rewrite ^/de(.*)$ http://www.example.de$1 permanent;
rewrite ^/en(.*)$ http://www.example.com$1 permanent;
Run Code Online (Sandbox Code Playgroud)
Iva*_*lev 10
对POST请求使用307重定向将允许您保留POST数据.在你的情况下,这样的事情应该工作正常:
location ~ ^/de/api/(?<method>.*)$ {
if ($request_method = POST) {
return 307 http://www.example.com/api/$method$is_args$args;
}
# You can keep this for non-POST requests
rewrite ^/de/api/(.*) http://www.example.com/api/$1 redirect;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6451 次 |
| 最近记录: |