我在 Nginx 后面运行 Jenkins,并使用 Let's Encrypt 作为 SSL 证书。如果我通过 访问该网站https://jenkins.mydomain.de/
,一切都正常。但是当我通过 访问它时http://jenkins.mydomain.de/
,Firefox 会显示“连接已重置。”并且 curl 会显示“服务器的回复为空”
我该如何调试?我真的不知道在哪里寻找问题。nginx 日志不包含任何相关信息。我怀疑下面配置中有关端口 80 的部分被其他指令无效,但我不知道该如何调查。
$ curl -svL http://jenkins.mydomain.de/
* Hostname was NOT found in DNS cache
* Trying my.ip.add.ress...
* Connected to jenkins.mydomain.de (my.ip.add.ress) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.38.0
> Host: jenkins.mydomain.de
> Accept: */*
>
* Empty reply from server
* Connection #0 to host jenkins.mydomain.de left intact
当使用 telnet 与服务器通信时,只要我按一次回车键(即 之后GET / HTTP/1.1
),连接就会关闭。
尽管 Firefox 的 SSL 证书没有问题,但 curl 却有:
$ curl -svL https://jenkins.mydomain.de/
* Hostname was NOT found in DNS cache
* Trying my.ip.add.ress...
* Connected to jenkins.mydomain.de (my.ip.add.ress) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
} [data not shown]
* SSLv3, TLS handshake, Server hello (2):
{ [data not shown]
* SSLv3, TLS handshake, CERT (11):
{ [data not shown]
* SSLv3, TLS alert, Server hello (2):
} [data not shown]
* SSL certificate problem: unable to get local issuer certificate
* Closing connection 0
* SSLv3, TLS alert, Client hello (1):
} [data not shown]
我的 Nginx 配置:
upstream jenkins {
server localhost:8080 fail_timeout=0;
}
server {
listen 80 default;
server_name jenkins.mydomain.de;
return 301 https://$server_name$request_uri;
# Replacing $server_name with $host does not work either.
}
server {
listen 443 default ssl;
server_name jenkins.mydomain.de;
ssl on;
ssl_certificate /etc/letsencrypt/live/jenkins.mydomain.de/cert.pem;
ssl_certificate_key /etc/letsencrypt/live/jenkins.mydomain.de/privkey.pem;
ssl_ciphers HIGH:!ADH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_session_timeout 5m;
ssl_session_cache builtin:1000 shared:SSL:10m;
location / {
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_set_header X-Forwarded-Proto $scheme;
proxy_redirect http://localhost:8080 https://$server_name;
proxy_pass https://jenkins;
}
}
Nginx 正在监听 80 端口:
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3895/nginx
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1048/sshd
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 3895/nginx
tcp6 0 0 :::41117 :::* LISTEN 19911/java
tcp6 0 0 :::8080 :::* LISTEN 19911/java
tcp6 0 0 :::22 :::* LISTEN 1048/sshd
tcp6 0 0 :::49208 :::* LISTEN 19911/java
答案1
使用server
与您相同的块进行端口 80 和 301 重定向,它在我的设置上与 Jenkins 一起工作(我不认为应用程序后端有任何影响,但只是为了确保万无一失)。我遇到的问题是防火墙没有打开 80 端口。你应该验证你自己的防火墙。