V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
yangzh
V2EX  ›  NGINX

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

  •  
  •   yangzh · 2014-07-02 16:21:06 +08:00 · 5307 次点击
    这是一个创建于 3583 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我用的是 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
       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
       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
       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
       2014-07-02 17:25:54 +08:00   ❤️ 1
    @yangzh 不客气,很高兴能够帮上你。有任何 NGINX 或者 Linux 服务器使用上遇到的问题就到 V2EX 讨论吧。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4458 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 04:06 · PVG 12:06 · LAX 21:06 · JFK 00:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.