1
cxbig 2016 年 4 月 28 日 加个条件试试
if ($scheme = http) { return 301 https://$server_name$request_uri; } |
2
stabc 2016 年 4 月 28 日 提这种问题记得要贴全配置,免得让想帮你的人瞎猜。
|
3
lslqtz 2016 年 4 月 28 日 你这是填在 listen 443;内了吧。。
我是直接用 listen 80; 然后直接 return 301 。 listen 443 则按正常来,贴一下我的配置文件 server { listen 80; index index.php index.htm index.html; root /var/www/html; return 301 https://www.hardwareunion.com$request_uri; location ~ .*\.(php|php5)?$ { fastcgi_pass unix:/var/run/phpfpm.sock; fastcgi_index index.php; include fastcgi.conf; } } server { listen 443 ssl http2; index index.php index.htm index.html; root /var/www/html; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; ssl_certificate /etc/nginx/1.crt; ssl_certificate_key /etc/nginx/1.key; ssl_ct on; ssl_ct_static_scts /etc/nginx/sct1; location ~ .*\.(php|php5)?$ { fastcgi_pass unix:/var/run/phpfpm.sock; fastcgi_index index.php; include fastcgi.conf; } } |
4
lslqtz 2016 年 4 月 28 日 妈蛋。。下面的 server_name 去了,上面 return 的忘去了。。噗
|
5
knightdf 2016 年 4 月 28 日 循环重定向了吧。。
|
6
usernametoolong 2016 年 4 月 28 日 一楼已给答案
|
7
xustrive 2016 年 4 月 28 日 留个记号。 下次好找~~~ 一脸闷 B 看不懂 逃····
|
8
ceoimon 2016 年 4 月 28 日 为什么不用 HSTS
|
9
nopicsayjb 2016 年 4 月 28 日 @ITOutsider
这或者是正确代码( 100%解决~),参考 if ($server_port = 80){ return 301 https://$server_name$request_uri;} if ($scheme = http){ return 301 https://$server_name$request_uri;} error_page 497 https://$server_name$request_uri; |
10
ldsink 2016 年 4 月 29 日 推荐一个网站
https://mozilla.github.io/server-side-tls/ssl-config-generator/ 自动生成正确的 Nginx SSL 配置,默认开启了 HSTS 。 你用这个配置按需求减就好。 |
11
ITOutsider OP |
12
kmdd33 2017 年 4 月 8 日
@cxbig 请问你这个 if ($scheme = http) {
return 301 https://$server_name$request_uri; } 可以添加在 nginx.conf 里面的 server {}段里面的任意位置吗?我也遇到了重定向次数过多的问题。 |
13
kmdd33 2017 年 4 月 8 日
@lHUAC 请问你这个 代码
if ($server_port = 80){ return 301 https://$server_name$request_uri;} if ($scheme = http){ return 301 https://$server_name$request_uri;} error_page 497 https://$server_name$request_uri; 可以添加在 nginx.conf 里面的 server {}段里面的任意位置吗? |
14
cxbig 2017 年 4 月 8 日
@kmdd33 从你另一个帖子 https://www.v2ex.com/t/353371 看,配置文件很乱。
通常我们很少直接去改 nginx.conf 文件 我不知道你用的哪个 Linux 发行版,最好在你那个帖子说明一下。 拿 Ubuntu Server 来说,不用改主配置文件。 有个目录用来放你自己的网站定义:/etc/nginx/sites-available 当你需要把一个网站上线的时候,把该目录的配置文件( vhost )做 Link 到:/etc/nginx/sites-enabled 再 reload 或 restart nginx 即可,你还可以用 service nginx configtest 来检查有没有语法错误 这是第一步,建议你弄清楚 nginx 的基本配置结构再说。 |
16
nopicsayjb 2017 年 4 月 12 日
|