简体   繁体   English

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

[英]NGiNX - redirect to https is unable to rewrite/replace correct wildcard char by originally requested sub-domain

I am using NGiNX server for one of my application . 我正在为其中一个application使用NGiNX服务器。

my application domain is, example.com 我的应用程序example.com

I have a kind of requirement to generate sub-domain on the fly bases . 我有一种要求, 可以根据需要动态生成子域

so that I have configured NGiNX something likewise in order to fulfil the sub-domain(business) requirements. 这样我就已经对NGiNX进行了一些配置,以满足子域(业务)的要求。

My NGiNX configure is likewise, 我的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
    }
.....

} }

The above mentioned configuration working perfectly but that's for HTTP not for HTTPS . 上面提到的配置可以正常运行但是用于HTTP而不用于HTTPS

I am reviewing the following things, 我正在审查以下内容,

My expected URL is, https://today.example.com after successfully redirection happen to a secure(301) channel. 成功重定向到安全(301)频道后,我的预期 URL为https://today.example.com

It's Redirecting me to here, 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://%2A.example.com/abc?abc=xyz (%2A is *, looks encoding scheme rewrite * -> %2A instead of today)

Instead of it, it should be https://today.example.com/abc?abc=xyz 取而代之的https://today.example.com/abc?abc=xyz

So, how to overcome on this handling *(wildcard char) in order to redirect successfully. 因此,如何克服这种处理*(通配符)以成功重定向。

Any help would really appreciable !! 任何帮助都将非常可观!

You need $host and not $server_name in the redirect statement. 您在重定向语句中需要$host而不是$server_name $server_name is the name configured in nginx, ie *.example.com . $server_name是在nginx中配置的名称,即*.example.com $host is instead the name as used by the client to reach the server and which was given inside an absolute URI or the Host header, ie today.example.com : $host是客户端用来访问服务器的名称,它是在绝对URI或Host标头中给出的,即today.example.com

return 301 https://$host$request_uri;

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

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