Docker nginx can';不要同时使用http和https
我正在使用最新的docker nginx。我想同时使用http和https访问我的网站。这是到目前为止我的nginx配置: default.cnf 但是当我访问我的服务器时,只有http是有效的。对于https,nginx将提供二进制日志:Docker nginx can';不要同时使用http和https,docker,nginx,Docker,Nginx,我正在使用最新的docker nginx。我想同时使用http和https访问我的网站。这是到目前为止我的nginx配置: default.cnf 但是当我访问我的服务器时,只有http是有效的。对于https,nginx将提供二进制日志: nginx | 120.236.174.140 - - [06/Apr/2018:19:04:40 +0000] "\x16\x03\x01\x00\xC3\x01\x00\x00\xBF\x03\x03T\xF7v\x15gk\x
nginx | 120.236.174.140 - - [06/Apr/2018:19:04:40 +0000] "\x16\x03\x01\x00\xC3\x01\x00\x00\xBF\x03\x03T\xF7v\x15gk\x04\xE2\xC5\xB3\x8B\x10\xAA\xE0\x1C\xA4[\xCE\x01z\xCC\x81\x19\x93\xC6\x11T5\x02\xD7$7\x00\x00\x1CZZ\xC0+\xC0/\xC0,\xC00\xCC\xA9\xCC\xA8\xC0\x13\xC0\x14\x00\x9C\x00\x9D\x00/\x005\x00" 400 174 "-" "-" "-"
以及curl
,如下所示:
kangbb@udo:~$ curl -L https://example.com
curl: (35) gnutls_handshake() failed: An unexpected TLS packet was received.
我在哪里写的错?谁能给我一些建议吗?多谢各位 你必须把它们分开。在一个假定的HTTP连接中有很多SSL的东西。取消对ssl的注释
on代码>在端口为443的端口中。创建另一台侦听端口80的服务器
upstream backends {
server app:8080;
}
server {
listen 443 ssl;
server_name example.com;
# SSL
ssl on;
ssl_certificate /etc/ssl/certs/214577452530751.pem;
ssl_certificate_key /etc/ssl/certs/214577452530751.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#proxy to webs
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backends;
}
}
server {
listen 80;
server_name example.com;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backends;
}
}
你必须把它们分开。在一个假定的HTTP连接中有很多SSL的东西。取消对ssl的注释on代码>在端口为443的端口中。创建另一台侦听端口80的服务器
upstream backends {
server app:8080;
}
server {
listen 443 ssl;
server_name example.com;
# SSL
ssl on;
ssl_certificate /etc/ssl/certs/214577452530751.pem;
ssl_certificate_key /etc/ssl/certs/214577452530751.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
#proxy to webs
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backends;
}
}
server {
listen 80;
server_name example.com;
location / {
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backends;
}
}
对于docker niginx,它将为您提供两个端口,80和443。如果您想将其用于http,请绑定80;如果要将其用于https,请绑定443 对于docker niginx,它将为您提供两个端口80和443。如果您想将其用于http,请绑定80;如果要将其用于https,请绑定443 请提供更多详情。当你尝试它时发生了什么?好的,真的谢谢你!我所做的是按照您所说的修改default.conf
。我已经更新了我的问题,也许你可以从中得到更多的细节。我已经更新了我的例子。你的位置看起来太复杂了。如果要匹配所有路径,只需使用斜杠。请提供更多详细信息。当你尝试它时发生了什么?好的,真的谢谢你!我所做的是按照您所说的修改default.conf
。我已经更新了我的问题,也许你可以从中得到更多的细节。我已经更新了我的例子。你的位置看起来太复杂了。如果要匹配所有路径,只需使用斜杠本身。