我有两个服务器块。 两者都做了类似的事情:允许我使用https。
现在我只是想知道,在一种情况下,我redirect从http到https的所有stream量。 在另一个它似乎好像我允许HTTPS。
有人可以向我解释,有什么不同? 因为当我请求我的域名时,即使使用http://test.example.com ,我仍然可以在两种情况下redirect到https。
有什么区别吗?
这是两个文件:
server { listen 80; listen [::]:80; server_name test.example.com return 301 https://$server_name$request_uri; } server { listen 443 ssl http2; listen [::]:443 ssl http2; root /var/www/test/staging/current; index index.php index.html index.htm index.nginx-debian.html; server_name test.example.com; include snippets/ssl-test.example.com.conf; include snippets/ssl-params.conf; location / { try_files $uri $uri/ =404; } }
server { listen 80; listen [::]:80; listen 443 ssl http2; listen [::]:443 ssl http2; root /var/www/test/staging/current; index index.php index.html index.htm index.nginx-debian.html; server_name test.example.com; include snippets/ssl-test.example.com.conf; include snippets/ssl-params.conf; location / { try_files $uri $uri/ =404; } }
从你的问题的细节,文件2似乎接受通过http和https连接,而不必从一个redirect到另一个。
然而:
https ,如果检测到http则会导致redirect ssl-params.conf文件可能包含一个严格的传输安全标头,导致您的浏览器强制连接为https 第二个configuration不应该redirect。 当您testing第一个configuration之前,您的浏览器可能已经caching了redirect(一个caching,这是很难删除,尝试另一个浏览器(configuration文件))。
而当你匹配$scheme = http然后redirect的时候,你仍然可以使用redirect的第二个configuration。 这可以简化你的configuration。