我将nginx-proxy设置为运行应用程序服务器的Docker容器前面的反向代理。 它们在单独的Docker组合定义中定义。 出于某种原因,我得到了一个503 ,但我不知道为什么,我已经详细了解了nginx-proxy文档。
(我也打开这个作为github问题的nginx-proxy 。)
应用程序服务器最初为https提供了443的10443主机。 我切换到服务HTTP 80 10443暴露在主机上。
我可以从应用服务器直接curl,但通过nginx-proxy卷发抛出一个错误
我最初在443有nginx-proxy,但现在我把它换成了80 。
直到我添加default.crt和default.key ,我得到一个连接拒绝错误。 join后,我得到了503 。
curl http://foo.example.com:80/apidocs --verbose --insecure * Hostname was NOT found in DNS cache * Trying 10.xxx.. * Connected to foo.example.com (10.xxx) port 80 (#0) > GET /apidocs HTTP/1.1 > User-Agent: curl/7.35.0 > Host: foo.example.com > Accept: */* > < HTTP/1.1 503 Service Temporarily Unavailable * Server nginx/1.9.12 is not blacklisted < Server: nginx/1.9.12 < Date: Thu, 21 Apr 2016 17:26:16 GMT < Content-Type: text/html < Content-Length: 213 < Connection: keep-alive < <html> <head><title>503 Service Temporarily Unavailable</title></head> <body bgcolor="white"> <center><h1>503 Service Temporarily Unavailable</h1></center> <hr><center>nginx/1.9.12</center> </body> </html> * Connection #0 to host foo.example.com left intact
这是我对nginx-proxy的撰写定义。 我正在使用network_mode: bridge即使version: 2 network_mode: bridge 。
version: '2' # Not yet compatible with custom networks in v2 of Compose services: nginx: image: jwilder/nginx-proxy # Necessary until nginx-proxy fully supports Compose v2 networking network_mode: bridge ports: - "80:80" restart: always volumes: - "certs:/etc/nginx/certs:ro" - "nginx-log:/var/log/nginx" - "/var/run/docker.sock:/tmp/docker.sock:ro" volumes: certs: external: true nginx-log: external: true
这是我的应用服务器组成:
version: '2' services: database: image: sameersbn/postgresql:9.4-13 restart: always # Necessary until nginx-proxy fully supports Compose v2 networking network_mode: bridge ports: - "55433:5432" environment: - DB_USER=foo - DB_PASS=... - DB_NAME=foo_staging - USERMAP_UID=1000 volumes: - "foo-data:/var/lib/postgresql" foo: image: private-registry.example.com/dswb/foo:1.4.3 restart: always container_name: "dswb-foo" links: - "database:database" # Necessary until nginx-proxy fully supports Compose v2 networking network_mode: bridge ports: - "10443:80" volumes: - "certs:/home/rails/webapp/certs" environment: # - "CERT_NAME=example.com" - "VIRTUAL_HOSTNAME=foo.example.com" - "VIRTUAL_PORT=80" - "VIRTUAL_PROTO=http" command: "bash -c 'rake db:migrate && thin --port 80 --address 0.0.0.0 start'" volumes: foo-data: driver: local certs: external: true
由于我切换到80端口进行debugging,所以证书不太相关。 我有*.example.com的通配符证书。 如果nginx-proxy无法find它,我创build了一个名为foo.example.com的副本。 我尝试了这两个设置,而不是设置CERT_NAME 。 我现在也生成了dhparam东西。
root@8b02a7deb220:/etc/nginx/certs# ls -la total 48 drwxr-xr-x 2 root root 4096 Apr 21 18:15 . drwxr-xr-x 4 root root 4096 Apr 21 18:06 .. -rw------- 1 root root 3575 Apr 21 18:03 example.com.crt -rw-r--r-- 1 root root 769 Apr 21 18:03 example.com.dhparam.pem -rw------- 1 root root 1679 Apr 21 18:03 example.com.key -rw-r--r-- 1 root root 1838 Apr 21 18:03 default.crt -rw-r--r-- 1 root root 3268 Apr 21 18:03 default.key -rw------- 1 root root 3575 Apr 21 17:37 foo.example.com.crt -rw-r--r-- 1 root root 769 Apr 21 18:15 foo.example.com.dhparam.pem -rw------- 1 root root 1679 Apr 21 17:37 foo.example.com.key
这是我curl时在nginx-proxy日志中唯一显示的内容:
nginx.1 | foo.example.com 10.xxx - - [21/Apr/2016:17:26:16 +0000] "GET /apidocs HTTP/1.1" 503 213 "-" "curl/7.35.0"
应用程序服务器日志中没有显示任何内容,这意味着它看不到请求。
我如何debugging? 有没有更好的日志?
我将开始设置您的nginx日志进行debugging,然后检查,看看请求抛出503
server { #other config error_log /var/logs/nginx/example.com.error.log debug; #other config }
你说端口80到10443,你的Docker安装仍然在服务HTTPS? 如果是这样,请尝试将两者都设置为HTTP,并在Docker上使用较less混淆的端口10080。