Nginx 域方案重定向不包括子域
Nginx Domain scheme redirect excluding subdomain
假设我有一个名为 example.com 的域以及以下 'n' 个子域,所有子域都具有 'A' 记录到相同的 IP 地址(假设服务器 A)。
a.example.com,b.example.com,c.example.com ... z.example.com
还有另一个子域 'email.example.com',CNAME 设置为 'mailgun.org'。
现在我的服务器 A 具有以下 nginx 配置,其中我想将所有 HTTP 请求转发到 HTTPS。
server {
listen 80;
return 301 https://$host$request_uri;
}
还有一组代码块来处理对 443 的单个子域请求。
server {
listen 443 ssl;
server_name a.example.com;
//SSL Details
location / {
root /var/www/a/;
}
除了电子邮件之外的其他子域类似。example.com 指向 mailgun.org。
现在,
http://email.example.com they will be redirected to http://mailgun.com。 (在 DNS 级别)
http://example.com they will be redirected to https://example.com。 (在服务器级别)。
http://a.example.com they will be redirected to https://a.example.com。 (在服务器级别)
问题:
通过浏览器访问 http://example.com, when someone tries to visit http://email.example.com they are being redirected to https://email.example.com 后。由于我无法控制 mailgun.org,我可以处理电子邮件的 https 请求。example.com
有没有设置 nginx 配置,在每个 HTTP 请求中都将重定向到 HTTPS,除了电子邮件。example.com?
好的,我找到问题了。
我将 example.com 的 nginx 配置更改为不包含子域。
即,更改了以下行
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
如下,
add_header Strict-Transport-Security "max-age=31536000;" always;
以便浏览器现在不会将 header 添加到子域。
假设我有一个名为 example.com 的域以及以下 'n' 个子域,所有子域都具有 'A' 记录到相同的 IP 地址(假设服务器 A)。
a.example.com,b.example.com,c.example.com ... z.example.com
还有另一个子域 'email.example.com',CNAME 设置为 'mailgun.org'。
现在我的服务器 A 具有以下 nginx 配置,其中我想将所有 HTTP 请求转发到 HTTPS。
server {
listen 80;
return 301 https://$host$request_uri;
}
还有一组代码块来处理对 443 的单个子域请求。
server {
listen 443 ssl;
server_name a.example.com;
//SSL Details
location / {
root /var/www/a/;
}
除了电子邮件之外的其他子域类似。example.com 指向 mailgun.org。
现在, http://email.example.com they will be redirected to http://mailgun.com。 (在 DNS 级别)
http://example.com they will be redirected to https://example.com。 (在服务器级别)。
http://a.example.com they will be redirected to https://a.example.com。 (在服务器级别)
问题: 通过浏览器访问 http://example.com, when someone tries to visit http://email.example.com they are being redirected to https://email.example.com 后。由于我无法控制 mailgun.org,我可以处理电子邮件的 https 请求。example.com
有没有设置 nginx 配置,在每个 HTTP 请求中都将重定向到 HTTPS,除了电子邮件。example.com?
好的,我找到问题了。
我将 example.com 的 nginx 配置更改为不包含子域。
即,更改了以下行
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
如下,
add_header Strict-Transport-Security "max-age=31536000;" always;
以便浏览器现在不会将 header 添加到子域。