【问题标题】:nginx redirect matching servname and location in multi name vhostnginx在多名称vhost中重定向匹配的servname和位置
【发布时间】:2016-11-21 06:18:52
【问题描述】:

我正在使用 nginx/1.4.6 Ubuntu 14.04.4 LTS。 我有一个看起来以下列开头的 SSL 虚拟主机

server {
        listen 443 default_server ssl;
        server_name example1.com example2.com example3.com;

您将如何编写重定向,以便如果任何匹配 example2.com/location* 的内容被重新写入 example2.com/page.html?

谢谢

【问题讨论】:

    标签: nginx url-rewriting nginx-location


    【解决方案1】:

    有三个变量可以帮助您识别接受请求的服务器的名称:$host$http_host$server_name

    要执行问题中指示的外部重定向,您可以使用:

    location /location {
        return 301 $scheme://$host/page.html;
    }
    

    详情请见this document

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多