http://a.com http://www.a.com http://b.com http://www.b.com
全部 301 跳转至https://www.a.com
但是现在存在的问题是http://a.com会先跳转到https://a.com再跳转到https://www.a.com
本人是小白菜鸟,烦请各位大佬帮忙看看配置文件需要怎么修改,拜谢!
下面是 nginx 配置文件
server { listen 443 ssl http2 reuseport; server_name a.com www.a.com m.a.com b.com www.b.com m.b.com; index index.html index.htm index.php; root /home/www; ssl on; ssl_certificate /home/ssl/fullchain.pem; ssl_certificate_key /home/ssl/a.com.pem; ssl_dhparam /home/ssl/dhparam.pem; ssl_session_timeout 1d; ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; ssl_session_cache shared:SSL:50m; ssl_session_tickets on; ssl_stapling on; ssl_stapling_verify on; resolver 114.114.114.114 valid=300s; resolver_timeout 10s; if ($host = 'a.com') { return 301 https://www.a.com$request_uri; } if ($host = 'b.com') { return 301 https://www.a.com$request_uri; } if ($host = "www.b.com") { return 301 https://www.a.com$request_uri; } if (!-e $request_filename) { rewrite ^/(.*) /index.php?s=$1 last; } location ~ [^/]\.php(/|$) { fastcgi_pass unix:/dev/shm/php-fpm.sock; fastcgi_index index.php; include fastcgi.conf; fastcgi_param HTTPS on; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"; add_header X-Content-Type-Options nosniff; } error_page 404 500 /404.html; access_log /home/logs/nginx_access.log; error_log /home/logs/nginx_error.log; } server { listen 80; server_name a.com www.a.com b.com www.b.com; access_log off; error_log off; location / { return 301 https://www.a.com$request_uri; } } server { listen 80; server_name m.a.com m.b.com; access_log off; error_log off;location / { return 301 https://m.a.com$request_uri; } }
![]() | 1 KasuganoSoras 2019-09-07 13:07:34 +08:00 ![]() |
![]() | 2 KasuganoSoras 2019-09-07 13:09:12 +08:00 而且你的 HSTS 是 preload,也就是在访问之前就会预先跳转,然后就自动跳转了。 |
3 dcd OP KasuganoSoras 谢谢大佬! |