想通过nginx.conf将服务器URL重定向到服务器url / somestring。 在nginx.conf中的服务器标记中尝试了位置/ somestring {},该方法无效。 请提出我该如何实现。
答案 0 :(得分:0)
允许重定向多个域的nginx配置示例。 您也可以使用类似的方法来重定向路径。
map $http_host $redirect_destination {
hostnames;
default where-to-go-by-default;
my-domain where-to-redirect-my-domain;
}
server {
listen 80;
location / {
return 301 https://$redirect_destination/some-path;
}
}
答案 1 :(得分:0)
通过使用return指令,我们可以完全避免对正则表达式求值。请参阅documentation。
可以选择以下位置块来响应看起来像/site
,/site/page1/index.html
或/site/index.html
的请求URI。您可以了解有关位置阻止here的更多信息。
在您的情况下,它类似于:
location /old-url {
return 301 /new-url;