我想把 http://www.xxx.com ,http://xxx.com ,https://xxx.com 都指向到 https://www.xxx.com

2018-09-07 10:28:54 +08:00
 astome

我想把 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;
}
10314 次点击
所在节点    PHP
23 条回复
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;
...
}
```
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;
}
}
lzhd24
2018-09-07 10:39:33 +08:00
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;
}

...
...
...
}
```
fmumu
2018-09-07 12:23:53 +08:00
dns 别名 ➕http 转 https
imn1
2018-09-07 12:23:54 +08:00
chrome 69 好像已经实现了
huaxing0211
2018-09-07 12:29:39 +08:00
codingadog
2018-09-07 12:34:47 +08:00
不要乱用 xxx.com
可以用 example.com
Raynard
2018-09-07 12:36:38 +08:00
用面板去吧,哈哈哈哈
choicky
2018-09-07 13:23:29 +08:00
caddy 更简单。个人小站就 caddy 好了。
lfzyx
2018-09-07 13:25:13 +08:00
用 return 301 是正确的做法,用 if 和 rewrite 是错误的做法
Les1ie
2018-09-07 13:56:15 +08:00
@codingadog hhhhhhhhhhhhh 也曾尴尬过
h19981126g
2018-09-07 14:00:42 +08:00
80 端口下添加 return 301 https://$server_name$request_uri;
server_name 后面把所有域名加上
ydxred
2018-09-07 14:05:20 +08:00
@codingadog 哈哈哈哈哈 xxx.com 翻墙就知道是什么了
Tink
2018-09-07 14:06:18 +08:00
cloudflare page_rules
cncqw
2018-09-07 14:28:30 +08:00
yxy2829
2018-09-07 14:36:14 +08:00
@ydxred 有新发现哈哈
lzvezr
2018-09-07 14:41:33 +08:00
之前用跳转,现在直接关 80 端口
Sharuru
2018-09-07 14:44:56 +08:00
糙快猛:
1. 域名泛解析
2. ACME 申请 Let's Encrypt,自动设置,完事儿(
torment5524
2018-09-07 14:47:57 +08:00
<html>
<meta http-equiv="refresh" content="0;url=https://www.xxx.com/">
</html>
把另外两个页面的首页换成 index.html,内容换成上面的内容。。我是这么搞的。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/487012

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX