使用Nginx

时间:2018-05-11 14:41:38

标签: docker ssl nginx lets-encrypt taskwarrior

我有一个使用docker + taskserver + nginx反向代理的当前配置,当我使用task sync连接时,它失败了。

$ task sync
c: 1 Received record packet of unknown type 72
Syncing with task.reggi.com:80

Handshake failed.  An unexpected TLS packet was received.
Sync failed.  Could not connect to the Taskserver.

我认为发生的事情是taskserver守护程序与“普通”服务器不同,并且还在设置证书,nginx也是如此。 < /强>

  • 我在域上运行let的加密并收到了证书
  • 我已经pki/generate.ca
  • 我已经pki/generate.client reggi
  • 我在客户端上指出这些
  • 我尝试过将ca证书与客户端上的“加密证书”进行不同的组合
  

.taskrc

taskd.certificate=/Users/thomas/Desktop/cloud/taskserver/pki/reggi.cert.pem
taskd.key=/Users/thomas/Desktop/cloud/taskserver/pki/reggi.key.pem
taskd.ca=~/.task/both.pem
taskd.server=task.reggi.com:80
taskd.credentials=Private/Thomas Reggi/2f397682-40d8-4b83-a7f4-de2bda1a31f1
  

VARS

BITS=4096
EXPIRATION_DAYS=365
ORGANIZATION="REGGI CORP"
CN=task.reggi.com
COUNTRY=US
STATE="NEW YORK"
LOCALITY="NEW YORK"
  

配置

confirmation=1
extensions=/usr/local/libexec/taskd
ip.log=on
log=/var/log/taskd.log
pid.file=/tmp/taskd.pid
queue.size=10
request.limit=1048576
root=/var/taskd
server=0.0.0.0:53589
trust=strict
verbose=1
ca.cert=/var/taskd/pki/ca.cert.pem
server.cert=/etc/nginx/certs/task.reggi.com/fullchain.pem
server.key=/etc/nginx/certs/task.reggi.com/key.pem
client.key=/var/taskd/pki/client.key.pem
client.cert=/var/taskd/pki/client.cert.pem
  

服务器正在启动

taskserver_1         | 20180511T072403Z 1.2.0 info ==== taskd 1.2.0 6f5929c ====
taskserver_1         | 20180511T072403Z 1.2.0 info Serving from /var/taskd
taskserver_1         | 20180511T072403Z 1.2.0 info Using address 0.0.0.0
taskserver_1         | 20180511T072403Z 1.2.0 info Using port 53589
taskserver_1         | 20180511T072403Z 1.2.0 info Using family
taskserver_1         | 20180511T072403Z 1.2.0 info Queue size 10 requests
taskserver_1         | 20180511T072403Z 1.2.0 info Request size limit 1048576 bytes
taskserver_1         | 20180511T072403Z 1.2.0 info IP logging on
taskserver_1         | 20180511T072403Z 1.2.0 info CA          /var/taskd/pki/ca.cert.pem
taskserver_1         | 20180511T072403Z 1.2.0 info Certificate /etc/nginx/certs/task.reggi.com/fullchain.pem
taskserver_1         | 20180511T072403Z 1.2.0 info Private Key /etc/nginx/certs/task.reggi.com/key.pem
taskserver_1         | 20180511T072403Z 1.2.0 info Server starting
taskserver_1         | 20180511T072403Z 1.2.0 info Using dh_bits: 0

当我将let的加密证书和客户端身份验证的ca证书结合起来时,我有时会得到这个:

$ task sync
c: 1 There was a non-CA certificate in the trusted list: CN=task.reggi.com.
c: 1 Received record packet of unknown type 72
Syncing with task.reggi.com:80

Handshake failed.  An unexpected TLS packet was received.
Sync failed.  Could not connect to the Taskserver.

我也遵循了上面描述的一些设置来匹配本教程,但仍然没有运气。

https://taskwarrior.org/support/faq.html#q12

潜在客户:来自Debian的这个老问题说明:

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=806426

  

我的错误防火墙规则是443-> 4443端口转发   能够在非特权端口上运行服务器。

     

我很抱歉。禁用此防火墙规则后,我就可以连接了   所有https都没有问题。

这是我的nginx配置。

# 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 X-Forwarded-Port, pass it through; otherwise, pass along the
# server port the client connected to
map $http_x_forwarded_port $proxy_x_forwarded_port {
  default $http_x_forwarded_port;
  ''      $server_port;
}
# 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;
}
# Apply fix for very long server names
server_names_hash_bucket_size 128;
# Default dhparam
# Set appropriate X-Forwarded-Ssl header
map $scheme $proxy_x_forwarded_ssl {
  default off;
  https on;
}
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_request_buffering off;
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;
proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
# 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;
}
# registry.reggi.com
upstream registry.reggi.com {
                ## Can be connected with "webproxy" network
            # main_registry_1
            server 172.19.0.6:80;
}
server {
    server_name registry.reggi.com;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    return 301 https://$host$request_uri;
}
server {
    server_name registry.reggi.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:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-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/registry.reggi.com.crt;
    ssl_certificate_key /etc/nginx/certs/registry.reggi.com.key;
    ssl_dhparam /etc/nginx/certs/registry.reggi.com.dhparam.pem;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/nginx/certs/registry.reggi.com.chain.pem;
    add_header Strict-Transport-Security "max-age=31536000" always;
    include /etc/nginx/vhost.d/default;
    location / {
        proxy_pass http://registry.reggi.com;
    }
}
# task.reggi.com
upstream task.reggi.com {
                ## Can be connected with "webproxy" network
            # main_taskserver_1
            server 172.19.0.3:53589;
}
server {
    server_name task.reggi.com;
    listen 80 ;
    access_log /var/log/nginx/access.log vhost;
    return 301 https://$host$request_uri;
}
server {
    server_name task.reggi.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:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-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/task.reggi.com.crt;
    ssl_certificate_key /etc/nginx/certs/task.reggi.com.key;
    ssl_dhparam /etc/nginx/certs/task.reggi.com.dhparam.pem;
    ssl_stapling on;
    ssl_stapling_verify on;
    ssl_trusted_certificate /etc/nginx/certs/task.reggi.com.chain.pem;
    add_header Strict-Transport-Security "max-age=31536000" always;
    include /etc/nginx/vhost.d/default;
    location / {
        proxy_pass http://task.reggi.com;
    }
}

Github问题:https://github.com/GothenburgBitFactory/taskserver/issues/141

:UPDATE:

我取得了很大的进步。

我删除了docker-compose.yml中所有nginx特定的内容,只剩下taskserver然后我将端口更改为443:53589,而我正在运行的数字海洋服务器暴露了端口443.所以我能够在没有nginx的情况下运行Taskserver。在客户端我不得不删除端口80,因为taskserver在443上公开,所以我将配置更改为读取taskd.server=task.reggi.com:443我做的另一件事就是让我工作的是我将taskd.ca=指向客户端下载了我们加密证书https://letsencrypt.org/certs/letsencryptauthorityx3.pem.txt然后我运行了task sync它就有效了!

...然而

当我恢复nginx配置时,它无法再次运行。

➜  cloud git:(master) task sync
Syncing with task.reggi.com:443

Handshake failed.  Error in the certificate.
Sync failed.  Could not connect to the Taskserver.
➜  cloud git:(master) task sync
c: 1 Received record packet of unknown type 72
Syncing with task.reggi.com:80

Handshake failed.  An unexpected TLS packet was received.
Sync failed.  Could not connect to the Taskserver.

0 个答案:

没有答案