我正在使用NGiNX
服务器作为我的一个application
。
我的应用程序域是,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
。
我正在审查以下事情,
我预期的URL 是,成功重定向后https://today.example.com
发生到安全(301( 通道。
它正在将我重定向到这里,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;