我通过 startssl 认证将我的网站升级到 https。 但是 Safari 不信任 startssl 认证。 所以,我考虑设置nginx,如果是http,并且UserAgent不包含iPhone/iPad,那么301重定向到https。(意思是其他浏览器会301到https。) 这是我试过的:
server {
listen 80;
listen 443 ssl;
server_name abc.com alias abc.com;
ssl_certificate D:\cert\1_abc.com_bundle.crt;
ssl_certificate_key D:\cert\abc.com.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
if ($scheme = http) && if ($http_user_agent !~* iPhone|iPad) {
return 301 https://$host$request_uri;
}
location / {
root D:/www;
index index.html index.htm default.html default.htm index.php;
include D:/www/up-*.conf;
}
========或==========
if ($scheme = http && $http_user_agent !~* iPhone|iPad)
========或==========
但两者都没有效果。
最佳答案
if
指令只能包含简单的条件。参见 this document了解详情。
一种方法是将 http
和 https
服务器分成单独的 server
block 。
server {
listen 80;
server_name abc.com alias abc.com;
if ($http_user_agent !~* "iPhone|iPad") {
return 301 https://$host$request_uri;
}
include path/to/common/config;
}
server {
listen 443 ssl;
server_name abc.com alias abc.com;
ssl_certificate D:\cert\1_abc.com_bundle.crt;
ssl_certificate_key D:\cert\abc.com.key;
ssl_session_timeout 5m;
ssl_protocols SSLv2 SSLv3 TLSv1;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
include path/to/common/config;
}
它确实涉及在两个 server
block 之间复制通用配置,但是,include
指令可用于将任何通用配置卸载到单独的文件中(如上所示)。
关于ssl - Nginx 配置 : if not iPhone/iPad then 301 redirect to https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41724280/