2017-06-21 44 views
-1

兩天的工作,我仍然堅持。我正在運行單獨的nginx和應用程序容器。應用程序容器有一個燒瓶應用程序,在端口8000上運行gunicorn進程。nginx和燒瓶碼頭集裝箱504錯誤

每次我導航到localhost:8080這是nginx端口80映射到本地主機,我得到一個加載屏幕和一個nginx 504錯誤。

這是我看到的終端上:enter image description here

泊塢窗,compose.yml

version: '2' 

services: 
    web: 
    restart: always 
    build: ./web_app 
    expose: 
     - "8000" 
    ports: 
     - "8000:8000" 
    volumes: 
     - ./web_app:/data/web 
    command: /usr/local/bin/gunicorn web_interface:app -w 4 -t 90 --log-level=info -b :8000 --reload 
    depends_on: 
     - postgres 

    nginx: 
    restart: always 
    build: ./nginx 
    ports: 
    - "8080:80" 
    volumes_from: 
     - web 
    depends_on: 
     - web 

    postgres: 
    restart: always 
    image: postgres:latest 
    volumes_from: 
     - data 
    volumes: 
     - ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d 
     - ./backups/postgresql:/backup 
    expose: 
     - "5432" 

    data: 
    restart: always 
    image: alpine 
    volumes: 
     - /var/lib/postgresql 
    tty: true 

nginx.conf

server { 

    listen 80; 
    server_name localhost; 
    charset utf-8; 

    location /static/ { 
     alias /data/web/crm/web_interface; 
    } 

    location = /favicon.ico { 
     alias /data/web/crm/web_interface/static/favicon.ico; 
    } 

    location/{ 
     proxy_pass http://web:8000; 
     proxy_set_header Host $host; 
     proxy_set_header X-Real-IP $remote_addr; 
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    } 
} 

nginx的Dockerfile

FROM nginx:latest 

RUN rm /etc/nginx/conf.d/default.conf 

COPY ./nginx.conf /etc/nginx/conf.d/nginx.conf 

我會提供更多的信息,如果需要得到一些關於我在掙扎的這個問題上的幫助。

+0

你能直接在'localhost:8000'上訪問gunicorn服務器嗎? –

+0

不,我嘗試過沒有成功。 –

+0

這是有道理的,我可以訪問它與暴露的端口和映射,但我仍然不能。 –

回答

0

好了,後撲我的頭三天,我重新從頭開始。重建應用程序容器並運行gunicorn。

從那裏我可以確定gunicorn進程超時,因爲數據庫主機名是不正確的。而不是通過我的應用程序返回的錯誤,失敗失敗。

我通過鏈接postgres容器和web容器來解決這個問題。在我的代碼中,我能夠使用「postgres」(容器的名稱)作爲postgres主機名。

檢查您的外部主機的地址。

0

NGINX響應504指示網關超時,因爲NGINX無法連接後端服務器。因此,您可以在proxy_pass目錄找到問題。

我想NGINX無法解析web域名,在兩個解決方案:

  1. 而不是IP

    位置/ {

    proxy_pass http://<real_ip>:8000; 
    

    }

  2. 使用上游

    上游捲筒紙{

    server <real_ip>; 
    

    }

    位置/ {

    proxy_pass http://web:8000; 
    proxy_set_header Host $host; 
    proxy_set_header X-Real-IP $remote_addr; 
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    

    }