【问题标题】:503 Service Temporarily Unavailable nginx/1.13.3 in docker503 Service Temporarily Unavailable nginx/1.13.3 in docker
【发布时间】:2018-06-22 14:41:41
【问题描述】:

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

第一步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实例的Security Group中打开端口80,尝试连接ip:80/,但是报错如下503 Service Temporarily Unavailable nginx/1.13 .3

码头工人日志说:

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"

【问题讨论】:

    标签: docker nginx


    【解决方案1】:

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

    这里的关键是“来自另一个容器的主机名”。当您尝试像您所说的那样连接 IP 时,Nginx 不会代理转发您。

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

    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,就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 2011-09-12
      • 2023-01-08
      • 2018-02-24
      • 1970-01-01
      相关资源
      最近更新 更多