我想把 http://www.xxx.com ,http://xxx.com ,https://xxx.com 都指向到 https://www.xxx.com - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
astome
V2EX    PHP

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

  •  
  •   astome 2018-09-07 0:28:54 +08:00 10971 次点击
    这是一个创建于 2592 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我想把 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; } 
    23 条回复    2018-09-07 21:58:49 +08:00
    AlphaTr
        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;
    ...
    }
    ```
    MaiCong
        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;
    }
    }
    lzhd24
        3
    lzhd24  
       2018-09-07 10:39:33 +08:00 via Android
    dimlau
        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;
    }

    ...
    ...
    ...
    }
    ```
    fmumu
        5
    fmumu  
       2018-09-07 12:23:53 +08:00 via Android
    dns 别名 http 转 https
    imn1
        6
    imn1  
       2018-09-07 12:23:54 +08:00
    chrome 69 好像已经实现了
    huaxing0211
        7
    huaxing0211  
       2018-09-07 12:29:39 +08:00
    Duolingo
        8
    Duolingo  
       2018-09-07 12:34:47 +08:00 via Android   1
    不要乱用 xxx.com
    可以用 example.com
    IsA26hN4DcQDS7Z9
        9
    IsA26hN4DcQDS7Z9  
       2018-09-07 12:36:38 +08:00
    用面板去吧,哈哈哈哈
    choicky
        10
    choicky  
       2018-09-07 13:23:29 +08:00 via iPhone
    caddy 更简单。个人小站就 caddy 好了。
    lfzyx
        11
    lfzyx  
       2018-09-07 13:25:13 +08:00
    用 return 301 是正确的做法,用 if 和 rewrite 是错误的做法
    Les1ie
        12
    Les1ie  
       2018-09-07 13:56:15 +08:00
    @codingadog hhhhhhhhhhhhh 也曾尴尬过
    h19981126g
        13
    h19981126g  
       2018-09-07 14:00:42 +08:00
    80 端口下添加 return 301 https://$server_name$request_uri;
    server_name 后面把所有域名加上
    ydxred
        14
    ydxred  
       2018-09-07 14:05:20 +08:00
    @codingadog 哈哈哈哈哈 xxx.com 翻墙就知道是什么了
    Tink
        15
    Tink  
    PRO
       2018-09-07 14:06:18 +08:00
    cloudflare page_rules
    cncqw
        16
    cncqw  
       2018-09-07 14:28:30 +08:00
    yxy2829
        17
    yxy2829  
       2018-09-07 14:36:14 +08:00
    @ydxred 有新发现哈哈
    lzvezr
        18
    lzvezr  
       2018-09-07 14:41:33 +08:00 via Android
    之前用跳转,现在直接关 80 端口
    Sharuru
        19
    Sharuru  
       2018-09-07 14:44:56 +08:00
    糙快猛:
    1. 域名泛解析
    2. ACME 申请 Let's Encrypt,自动设置,完事儿(
    torment5524
        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,内容换成上面的内容。。我是这么搞的。
    wwwiamdog
        22
    wwwiamdog  
       2018-09-07 15:04:27 +08:00
    别这样我都点了。
    choicky
        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 了。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     1537 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 24ms UTC 16:19 PVG 00:19 LAX 09:19 JFK 12:19
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86