知道 V2 大神多,折腾了好久也没搞明白,求大神知道一下。 目的是为了让 www.nimohunter.com nimohunter.com 都用各自的证书实现 https 访问 但是现在配置了好久,只有 nimohunter.com 是有效的, www.nimohunter.com 一直会使用 nimohunter.com 的证书,所以会一直报错。
使用的是 Let's encrypt 的证书。
nginx 配置文件如下: default.conf
# If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
# scheme used to connect to this server
map $http_x_forwarded_proto $proxy_x_forwarded_proto {
default $http_x_forwarded_proto;
'' $scheme;
}
# If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
# Connection header that may have been passed to this server
map $http_upgrade $proxy_connection {
default upgrade;
'' close;
}
gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
log_format vhost '$host $remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log off;
# HTTP 1.1 support
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
# Mitigate httpoxy attack (see README for details)
proxy_set_header Proxy "";
server {
server_name _; # This is just an invalid value which will never trigger on a real hostname.
listen 80;
access_log /var/log/nginx/access.log vhost;
return 503;
}
upstream nimohunter {
# nginx
server 172.17.0.3:80;
}
server {
server_name www.nimohunter.com nimohunter.com;
listen 80 ;
access_log /var/log/nginx/access.log vhost;
return 301 https://$host$request_uri;
}
server {
server_name www.nimohunter.com;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
ssl_prefer_server_ciphers on;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_certificate /etc/nginx/certs/www.nimohunter.com.crt;
ssl_certificate_key /etc/nginx/certs/www.nimohunter.com.key;
add_header Strict-Transport-Security "max-age=31536000";
location / {
proxy_pass http://nimohunter;
}
}
server {
server_name nimohunter.com;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers 'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
ssl_prefer_server_ciphers on;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_certificate /etc/nginx/certs/nimohunter.com.crt;
ssl_certificate_key /etc/nginx/certs/nimohunter.com.key;
add_header Strict-Transport-Security "max-age=31536000";
location / {
proxy_pass http://nimohunter;
}
}
各位能告诉小弟哪里配置有问题吗...
终于配置好了,Let's encript可以支持多个domian,然后简单点,三部可以弄好:
docker run -d -p 80:80 -p 443:443 --name=proxy --restart=always -v /var/local/nginx/certs:/etc/nginx/certs -v /etc/letsencrypt:/etc/letsencrypt -v /var/local/proxy-confs:/etc/nginx/vhost.d:ro -v /var/run/docker.sock:/tmp/docker.sock:ro -v /nimo_nginx_confAndcontent/html:/usr/share/nginx/html -v /nimo_nginx_confAndcontent/conf.d:/etc/nginx/conf.d nginx
docker run -d --restart=always --name=web -v /nimo_www/html:/usr/share/nginx/html nginx
然后注意一下证书的位置就好了,证书放在了 host的 /etc/letsencrypt, 并且还有 ln -s /var/local/nginx/certs的软连接
./certbot-auto certonly --standalone --email [email protected] -d example.com -d www.example.com -d other.example.net
改成这些
ssl_certificate /etc/nginx/certs/shared.crt;
ssl_certificate_key /etc/nginx/certs/shared.key;
可以结束这个帖子了,多谢各位
1
ppwangs 2016-10-11 11:51:54 +08:00
我就配了三行就可以了
ssl on; ssl_certificate /etc/nginx/ca/certificate.crt; ssl_certificate_key /etc/nginx/ca/private.key; |
2
walkershow 2016-10-11 15:06:47 +08:00
同楼上,是不是证书要弄成 nginx 的格式
|
3
toposort 2016-10-11 15:09:17 +08:00 1
同一个 server 的同一个端口只有一个证书生效。
原因大概就是握手的时候 server 并不知道 host ,所以一般就配的第一个 host 生效,访问第二个 host 的话,证书报错。 解决方案: 1 、如果用 LVS 的话, nginx 使用不同端口,前面搞两个 LVS 2 、多个域名使用同一个证书 3 、还有一个叫 SNI 的扩展,不过是双边的,需要浏览器支持 |
4
msg7086 2016-10-11 15:47:20 +08:00 via Android
我就好奇你为啥要分成两张证书搞。
|
5
Duluku OP |
6
Duluku OP @toposort
多谢你的回复,觉得第一种方法应该可行,我去试试,到时候来回复你。第二种我没有什么把握,不知道这个 let's encrypt 能不能对两个域名签出一个证书。第三种…挺厉害的… 不过可能不太会去使用… 不过还是感谢您的解决方案 |
7
Duluku OP @msg7086 我没有什么把握,不知道这个 let's encrypt 能不能对两个域名签出一个证书… 我去试试看
|
8
Duluku OP @toposort 不过我细想的一下, www 和 non www 的指向两个不同的 LVS ,感觉有点奇怪… 这么做合适吗?
|
9
liuminghao233 2016-10-11 20:38:10 +08:00
装个 VPS 面板配置方便
|
10
bestie 2016-10-11 20:54:32 +08:00
你可以签一个泛域名的证书, Google 一下就能找到免费的 AlphaSSL 证书。
|
14
hoperuin 2016-10-12 09:53:06 +08:00
|
15
Niphor 2016-10-12 12:30:01 +08:00
我家 NAS,也用 LE 签了好几个证书啊... 正常配置没啥位置啊
|
16
Niphor 2016-10-12 12:30:10 +08:00
没啥问题啊
|
17
xiaooloong 2016-10-12 13:55:27 +08:00 1
@toposort nginx 已经支持 SNI 了,同端口多域名的多证书是支持的。
|
18
Duluku OP @xiaooloong @Niphor @hoperuin @msg7086 @liuminghao233 @bestie 这几天在公司忙着工作,都没空回复各位,终于周末可以做了,多谢各位... 也是涨了知识了,多谢各位 V 友
|
19
Duluku OP @Niphor 终于配置好了,可以在一个证书里放多个 domain 的,是我孤陋寡闻了。。看文档的时候没注意... 再次多谢
|