加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

Nginx SSL /子域/ IP重定向

发布时间:2020-12-13 21:37:26 所属栏目:Nginx 来源:网络整理
导读:目前我正在运营一个网站 centOS7上的nginx / 1.6.3 除了一些重定向外,一切都运行顺畅. 这是我的.conf文件的样子: server { listen 443 ssl spdy default deferred; server_name .example.com; ... more configs }server { listen 80; server_name .example.

目前我正在运营一个网站
centOS7上的nginx / 1.6.3

除了一些重定向外,一切都运行顺畅.

这是我的.conf文件的样子:

server {
  listen 443 ssl spdy default deferred;
  server_name .example.com;

  ... more configs

  }


server {
  listen 80;
  server_name .example.com;
  return 301 https://example.com$request_uri;
}

我想要完成的是以下场景:

user visits in browser              | this should happen
------------------------------------|-------------------------------------
https://example.com$request_uri     | Just deliver content
https://*.example.com$request_uri   | 301 https://example.com$request_uri
https://123.123.123.123$request_uri | 301 https://example.com$request_uri
http://example.com$request_uri      | 301 https://example.com$request_uri
http://*.example.com$request_uri    | 301 https://example.com$request_uri
http://123.123.123.123$request_uri  | 301 https://example.com$request_uri
最佳答案
请检查以下配置运行,这应该工作.

#This would serve all your content.
server {
  listen 443 ssl spdy default deferred;
  server_name example.com;

  ... more configs

}

#https calls to anything except example.com would be redirected here    
server {
  listen 443 ssl spdy default deferred; #(Can also use only : "listen 443;")
  server_name *.example.com 123.123.123.123;
  return 301 https://example.com$request_uri;
}

#All port 80 redirection to https://example.com
server {
  listen 80;
  server_name example.com *.example.com 123.123.123.123;
  return 301 https://example.com$request_uri;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读