我想把 http://www.xxx.com ,http://xxx.com ,https://xxx.com 都指向到 https://www.xxx.com
nginx 怎么配置啊
在网站找的方法 老是重定向次数过多!
server{ listen 80; root /data/www/www.xxx.com; server_name www.xxx.com; }
server { listen 443 ssl http2; #listen [::]:443 ssl http2; server_name www.xxx.com xxx.com; index index.html index.htm index.php; root /data/www/www.xxx.com; ssl on; ssl_certificate /usr/local/nginx/conf/ssl/xxx.com.crt; ssl_certificate_key /usr/local/nginx/conf/ssl/xxx.com.key; ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_ciphers "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5"; ssl_session_cache builtin:1000 shared:SSL:10m; # openssl dhparam -out /usr/local/nginx/conf/ssl/dhparam.pem 2048 ssl_dhparam /usr/local/nginx/conf/ssl/dhparam.pem;
include rewrite/other.conf; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } include enable-php-pathinfo.conf; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } location ~ /.well-known { allow all; } location ~ /\. { deny all; } access_log /home/wwwlogs/www.xxx.com.log; }
![]() | 1 AlphaTr 2018-09-07 10:33:31 +08:00 我是这么配的,可以参考下: ``` server { listen 80; server_name xxx.com www.xxx.com; return 301 https://www.xxx.com$request_uri; } server { listen 443 ssl http2; server_name xxx.com; ssl on; ssl_certificate fullchain.ecdsa-256.crt; ssl_certificate_key privkey.ecdsa-256.key; return 301 https://www.xxx.com$request_uri; } server { listen 443 ssl http2; server_name www.xxx.com; root /xxx/www; index index.html; ... } ``` |
2 MaiCong 2018-09-07 10:34:47 +08:00 server { listen 80; server_name xxx.com www.xxx.com; return 301 https://www.xxx.com$request_uri; } server { listen 443 ssl; server_name xxx.com www.xxx.com; if ($http_host != 'www.xxx.com' ) { return 301 https://www.xxx.com$request_uri; } } |
3 lzhd24 2018-09-07 10:39:33 +08:00 via Android |
![]() | 4 dimlau 2018-09-07 12:14:39 +08:00 我的: ``` server { listen 80; listen 443 ssl http2; server_name kaix.in *.kaix.in; index index.html index.php; root /home/wwwroot/kaixin; error_page 404 = /404.html; error_page 500 403 502 = /err.html; if ($host != 'kaix.in' ) { rewrite ^/(.*)$ https://kaix.in/$1 permanent; } if ($scheme != 'https' ) { rewrite ^/(.*)$ https://kaix.in/$1 permanent; } ... ... ... } ``` |
5 fmumu 2018-09-07 12:23:53 +08:00 via Android dns 别名 http 转 https |
![]() | 6 imn1 2018-09-07 12:23:54 +08:00 chrome 69 好像已经实现了 |
7 huaxing0211 2018-09-07 12:29:39 +08:00 |
![]() | 8 Duolingo 2018-09-07 12:34:47 +08:00 via Android ![]() |
![]() | 9 IsA26hN4DcQDS7Z9 2018-09-07 12:36:38 +08:00 用面板去吧,哈哈哈哈 |
10 choicky 2018-09-07 13:23:29 +08:00 via iPhone caddy 更简单。个人小站就 caddy 好了。 |
![]() | 11 lfzyx 2018-09-07 13:25:13 +08:00 用 return 301 是正确的做法,用 if 和 rewrite 是错误的做法 |
![]() | 12 Les1ie 2018-09-07 13:56:15 +08:00 @codingadog hhhhhhhhhhhhh 也曾尴尬过 |
![]() | 13 h19981126g 2018-09-07 14:00:42 +08:00 80 端口下添加 return 301 https://$server_name$request_uri; server_name 后面把所有域名加上 |
![]() | 14 ydxred 2018-09-07 14:05:20 +08:00 @codingadog 哈哈哈哈哈 xxx.com 翻墙就知道是什么了 |
![]() | 15 Tink PRO cloudflare page_rules |
![]() | 16 cncqw 2018-09-07 14:28:30 +08:00 |
![]() | 18 lzvezr 2018-09-07 14:41:33 +08:00 via Android 之前用跳转,现在直接关 80 端口 |
19 Sharuru 2018-09-07 14:44:56 +08:00 糙快猛: 1. 域名泛解析 2. ACME 申请 Let's Encrypt,自动设置,完事儿( |
![]() | 20 torment5524 2018-09-07 14:47:57 +08:00 <html> <meta http-equiv="refresh" cOntent="0;url=https://www.xxx.com/"> </html> 把另外两个页面的首页换成 index.html,内容换成上面的内容。。我是这么搞的。 |
![]() | 21 darrenliuwei1226 2018-09-07 14:56:16 +08:00 |
![]() | 22 wwwiamdog 2018-09-07 15:04:27 +08:00 别这样我都点了。 |
23 choicky 2018-09-07 21:58:49 +08:00 @astome 安利一个 nginx 的替代品 ,caddy,安装过程见我的博文 https://itlaws.cn/post/caddy-installation-ubuntu/ www.example.com { ... } example.com { redir https://www.example.com{uri} } 第一个大括号,就能让 www.example.com 的 http 跳转到 https 了。 第二个大括号,就能让 example.com 的 http/https 都跳转到 https://www.example.com 了。 |