[英]NGiNX - redirect to https is unable to rewrite/replace correct wildcard char by originally requested sub-domain
我正在为其中一个application
使用NGiNX
服务器。
我的应用程序域是example.com
我有一种要求, 可以根据需要动态生成子域 。
这样我就已经对NGiNX进行了一些配置,以满足子域(业务)的要求。
我的NGiNX配置也是一样,
server {
listen 80;
server_name *.example.com;
#access_log off;
.....
location / {
# redirect to secure site
return 301 https://$server_name$request_uri; # Here it's redirecting me along with * only instead of sub-domain name
}
.....
}
上面提到的配置可以正常运行,但是用于HTTP
而不用于HTTPS
。
我正在审查以下内容,
成功重定向到安全(301)频道后,我的预期 URL为https://today.example.com
。
它https://%2A.example.com/abc?abc=xyz (%2A is *, looks encoding scheme rewrite * -> %2A instead of today)
我重定向到这里https://%2A.example.com/abc?abc=xyz (%2A is *, looks encoding scheme rewrite * -> %2A instead of today)
取而代之的是https://today.example.com/abc?abc=xyz
因此,如何克服这种处理*(通配符)以成功重定向。
任何帮助都将非常可观!
您在重定向语句中需要$host
而不是$server_name
。 $server_name
是在nginx中配置的名称,即*.example.com
。 $host
是客户端用来访问服务器的名称,它是在绝对URI或Host
标头中给出的,即today.example.com
:
return 301 https://$host$request_uri;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.