Docker容器中的Nginx错误

时间:2018-05-06 14:16:23

标签: docker nginx

我有一个烧瓶应用程序,我正在尝试在docker容器中运行。 Docker-compose build和docker-compose up运行正常,但是当我去 localhost 时,我从nginx获得了502 Bad Gateway。这里有nginx错误日志

2018/05/06 14:06:37 [error] 10#10: *12 connect() failed (111: Connection refused) while connecting to upstream, client: 10.8.5.79, server: servername.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://10.21.50.9:8000/favicon.ico", host: "servername.com", referrer: "http://servername.com/"
10.8.5.79 - - [06/May/2018:14:06:37 +0000] "GET /favicon.ico HTTP/1.1" 502 575 "http://servername.com/" "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36" "-"

我的nginx.conf文件看起来像这样

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /var/log/nginx/access.log  main;

sendfile            on;
tcp_nopush          on;
tcp_nodelay         on;
keepalive_timeout   65;
types_hash_max_size 2048;

include             /etc/nginx/mime.types;
default_type        application/octet-stream;

include /etc/nginx/conf.d/*.conf;

server {
    listen       80 default_server;
    #listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
        proxy_pass http://127.0.0.1:8080;
    proxy_redirect off;
    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;
}


    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

}

有什么简单的我在这个conf中俯视吗?或者也许是nginx无法正常工作的另一个原因?

编辑添加的docker-compose.yml文件

版本:'2'

services:
 web:
   restart: always
   build: ./web
   expose:
     -"8000"
   volumes:
     - /usr/src/app/project/static
   command: /usr/local/bin/gunicorn -w 2 -b :8000 project:app

 nginx:
   restart: always
   build: ./nginx
   ports:
     - "80:80"
   volumes:
     - /www/static
   volumes_from:
     - web
   depends_on:
     - web

0 个答案:

没有答案