gpt4 book ai didi

http - NGiNX - 重定向到 https 无法通过最初请求的子域重写/替换正确的通配符字符

转载 作者:太空宇宙 更新时间:2023-11-03 13:50:10 25 4
gpt4 key购买 nike

我正在为我的一个应用程序使用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

我正在审查以下内容,

成功重定向后,我的预期 URL 是https://today.example.com 发生在安全(301) channel 上。

它把我重定向到这里,https://%2A.example.com/abc?abc=xyz(%2A 是 *,看起来编码方案重写 * -> %2A 而不是今天)

而不是它,它应该是https://today.example.com/abc?abc=xyz

那么,如何克服这种处理 *(wildcard char) 才能成功重定向。

任何帮助都非常有用!!

最佳答案

在重定向语句中需要 $host 而不是 $server_name$server_name是nginx中配置的名称,即*.example.com$host 是客户端用来访问服务器的名称,它是在绝对 URI 或 Host header 中给出的,即 today.example。 com:

return 301 https://$host$request_uri;

关于http - NGiNX - 重定向到 https 无法通过最初请求的子域重写/替换正确的通配符字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52791558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com