503服务暂时不可用在docker中的nginx / 1.13.3

时间:2017-08-14 13:44:29

标签: docker nginx

我正在尝试使用jwilder/nginx-proxy: alpine来启动nginx,以下是docker run命令和步骤:

第1步docker run -d -p 80:80 -p 443:443 -v /var/run/docker.sock:/tmp/docker.sock:ro --name nginx jwilder/nginx-proxy:alpine

Step2 :在ec2实例的安全组中打开端口80,并尝试连接到ip:80/,但错误如下 503暂时服务不可用的nginx / 1.13.3

docker logs说:

WARNING: /etc/nginx/dhparam/dhparam.pem was not found. A pre-generated dhparam.pem will be used for now while a new one
is being generated in the background.  Once the new dhparam.pem is in place, nginx will be reloaded.
forego     | starting dockergen.1 on port 5000
Generating DH parameters, 2048 bit long safe prime, generator 2
forego     | starting nginx.1 on port 5100
dockergen.1 | 2017/08/14 13:45:44 Generated '/etc/nginx/conf.d/default.conf' from 4 containers
dockergen.1 | 2017/08/14 13:45:44 Running 'nginx -s reload'
dockergen.1 | 2017/08/14 13:45:44 Watching docker events
dockergen.1 | 2017/08/14 13:45:44 Contents of /etc/nginx/conf.d/default.conf did not change. Skipping notification 'nginx -s reload'
nginx.1    | ec2-xx.xx.xxx.xx..ap-xyz-5.compute.amazonaws.com xx.xxx.xxx.x -     "GET / HTTP/1.1" 503 615 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"
nginx.1    | ec2-xx.xxx.xxxx.xxx.ap-xyz-5.compute.amazonaws.com xx.xx.xx.xxx  "GET /favicon.ico HTTP/1.1" 503 615 "http://ec2-xx.xxx.xx.xx.ap-xyz-5.compute.amazonaws.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"

1 个答案:

答案 0 :(得分:0)

jwilder/nginx-proxy并没有太大意义。魔术背后的脚本检查其他容器环境变量,并生成相应的规则以将代理从hostname from another container as defined in env var : port defined the same way反向到所述容器和端口。

此处的键是“来自另一个容器的主机名”。当您尝试使用您所说的IP连接时,Nginx不会代理转发您。

这是来自jwielder / nginx的github存储库中的README.md的示例

version: '2'

services:
  nginx-proxy:
    image: jwilder/nginx-proxy
    ports:
      - "80:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro

  whoami:
    image: jwilder/whoami
    environment:
      - VIRTUAL_HOST=whoami.local         <================

运行此命令,编辑您的主机文件(类似sudo vim /etc/hosts),然后添加[ec2ip] whoami.local,然后为http://whoami.local打开浏览器,就可以了。