如何在 nginx 和 apache 合用的网站上添加 ssl 支持? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
yangzh
V2EX    NGINX

如何在 nginx 和 apache 合用的网站上添加 ssl 支持?

  •  
  •   yangzh 2014-07-02 16:21:06 +08:00 5847 次点击
    这是一个创建于 4193 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我用的是 http://blog.linuxeye.com/31.html 这个 “LNMP、LAMP、LANMP一键安装脚本” 的默认配置,网站是 example.com,主页是 http://example.com/index.php。


    nginx 配置是

    # ....../nginx/conf/vhost/example.com.conf
    server {
    listen 80;
    server_name example.com;
    access_log off;
    index index.html index.htm index.jsp index.php;
    root /home/wwwroot/example.com;
    location / {
    try_files $uri @apache;
    }
    location @apache {
    internal;
    proxy_pass http://127.0.0.1:8080;
    }
    location ~ .*\.(php|php5)?$ {
    proxy_pass http://127.0.0.1:8080;
    }
    }


    apache 配置是

    # ......apache/conf/vhost/example.com.conf
    <VirtualHost *:8080>
    ServerAdmin [email protected]
    DocumentRoot "/home/wwwroot/example.com"
    ServerName example.com
    <Directory "/home/wwwroot/example.com">
    SetOutputFilter DEFLATE
    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    DirectoryIndex index.html index.php
    </Directory>
    </VirtualHost>



    生成了 example.com.csr 和 example.com.key ,给钱买了个证书 example.com.crt 。

    我应该怎样添加配置?比如说添加删除 apache nginx 的功能和写虚拟主机设置等等?使得又可以访问 http://example.com 又可以访问 https://example.com

    谢谢各位!
    7 条回复    2014-07-02 17:25:54 +08:00
    Livid
        1
    Livid  
    MOD
    PRO
       2014-07-02 16:23:02 +08:00   1
    理论上你只需要给 Nginx 加上 SSL 就可以了。Nginx 和后端的 Apache 通讯时还是继续用 http。
    yangzh
        2
    yangzh  
    OP
       2014-07-02 16:30:22 +08:00
    @Livid 我也是这样想的。最坑爹的是居!然!不!成!功!访问 https 没有响应。。。

    我是在 80 那个 server 下添加这么一个 server 的,但是我重启 nginx (成功重启)之后访问 https 没有响应的样子

    server{
    listen 443;
    ssl on;
    server_name example.com;
    ssl_certificate /secret/example.com.crt;
    ssl_certificate_key /secret/example.com.key;

    #以下都是全抄 80 的设置
    access_log off;
    index index.html index.htm index.jsp index.php;
    root /home/wwwroot/example.com;
    location / {
    try_files $uri @apache;
    }
    location @apache {
    internal;
    proxy_pass http://127.0.0.1:8080;
    }
    location ~ .*\.(php|php5)?$ {
    proxy_pass http://127.0.0.1:8080;
    }
    }
    Livid
        3
    Livid  
    MOD
    PRO
       2014-07-02 16:31:23 +08:00   1
    yangzh
        4
    yangzh  
    OP
       2014-07-02 16:45:06 +08:00
    @Livid 我觉得我很接近你这个官方指南了呀。。

    刚才,根据官方指南,我把 listen 443; ssl on; 改成了 listen 443 ssl; 添加了以下三行,还是不行。。。
    ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;

    访问 https://example.com/, chrome 显示 Google Chrome could not load the webpage because example.com took too long to respond.

    any ideas ?
    Livid
        5
    Livid  
    MOD
    PRO
       2014-07-02 16:53:24 +08:00   1
    @yangzh 防火墙没开 443 端口?
    yangzh
        6
    yangzh  
    OP
       2014-07-02 17:24:27 +08:00
    @Livid 终于!找出了问题所在!就是 iptables 限制住了!谢谢大神!
    Livid
        7
    Livid  
    MOD
    PRO
       2014-07-02 17:25:54 +08:00   1
    @yangzh 不客气,很高兴能够帮上你。有任何 NGINX 或者 Linux 服务器使用上遇到的问题就到 V2EX 讨论吧。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     5646 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 40ms UTC 01:41 PVG 09:41 LAX 17:41 JFK 20:41
    Do have faith in what you're doing.
    ubao msn 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