繁体   English   中英

想通过 nginx 将服务器 url 重定向到 server/somestring

[英]Want to redirect the server url to server/somestring through nginx

想通过 nginx.conf 将服务器 url 重定向到服务器 url/somestring。 在 nginx.conf 中的服务器标记内尝试 location /somestring{},没有用。 请建议我如何实现这一目标。

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;
    }
}

通过使用return指令,我们可以完全避免对正则表达式求值。 请参考文档

可以选择以下位置块来响应看起来像/site/site /site/page1/index.html /site /site/page1/index.html/site/index.html请求URI。 您可以在此处阅读更多有关位置限制的信息

在您的情况下,它类似于:

location /old-url {
  return 301 /new-url;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM