我想把 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 条回复
darrenliuwei1226
2018-09-07 14:56:16 +08:00
wwwiamdog
2018-09-07 15:04:27 +08:00
别这样我都点了。
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 了。

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

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

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

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

© 2021 V2EX