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

2014-07-02 16:21:06 +08:00
 yangzh
我用的是 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 admin@linuxeye.com
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

谢谢各位!
5318 次点击
所在节点    NGINX
7 条回复
Livid
2014-07-02 16:23:02 +08:00
理论上你只需要给 Nginx 加上 SSL 就可以了。Nginx 和后端的 Apache 通讯时还是继续用 http。
yangzh
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
2014-07-02 16:31:23 +08:00
yangzh
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
2014-07-02 16:53:24 +08:00
@yangzh 防火墙没开 443 端口?
yangzh
2014-07-02 17:24:27 +08:00
@Livid 终于!找出了问题所在!就是 iptables 限制住了!谢谢大神!
Livid
2014-07-02 17:25:54 +08:00
@yangzh 不客气,很高兴能够帮上你。有任何 NGINX 或者 Linux 服务器使用上遇到的问题就到 V2EX 讨论吧。

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

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

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

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

© 2021 V2EX