2016-07-24 203 views
1

我正在嘗試配置一個docker組合示例,其中包含運行uwsgi中的python應用程序的3個容器的nginx(運行在容器中)。當從本地主機訪問時出現404錯誤:NGINX uWSGI

當通過docker ip爲容器嘗試nginx時,該應用程序無需任何問題即可訪問;但是,當試圖從主機url(nginx綁定到使用端口9999的主機)訪問它時,使用localhost:9999我可以訪問nginx頁面,但是任何應用程序url或/ admin/uri都顯示404錯誤。

我已經經歷了噸論壇和Stackoverflow的答案沒有任何運氣,有人可以幫我解決這個問題嗎?下面附

的更多信息:

我的搬運工撰寫文件看起來象下面這樣:對於nginx的

version: '2' 
services: 
    nginxlb: 
    build: ./nginx 
    ports: 
     - "9999:80" 
    links: 
     - my-app1:my-app1 
     - my-app2:my-app2 
     - my-app3:my-app3 
    volumes: 
     - ./logs/nginx/:/opt/my-logs/nginx/ 
    my-app1: 
    build: ./my 
    expose: 
     - 8080 
     - 8081 
    volumes: 
     - ./logs/node1:/opt/my-logs/node1/ 
    my-app2: 
    build: ./my 
    volumes: 
     - ./logs/node2/:/opt/my-logs/node2/ 
    expose: 
     - 8080 
     - 8081 
    my-app3: 
    build: ./my 
    volumes: 
     - ./logs/node3:/opt/my-logs/node3 
    expose: 
     - 8080 
     - 8081 

啓用站點的conf如下所示:

upstream node-app { 
     least_conn; 
     server my-app1:8080; 
     server my-app2:8080; 
     server my-app3:8080; 
} 

server { 
     listen 80 default; 
     server_name _; 
     location/{ 
     proxy_pass http://node-app; 
     include /etc/nginx/uwsgi_params; 
     } 
} 

編輯這是我的NGINX的Docker文件我沒有對默認的nginx.conf文件做任何更改

From nginx 

MAINTAINER DevOps 

# Update the container 
RUN apt-get update 

# Create directories and set working directory 
RUN mkdir /opt/myapp/ 
RUN mkdir /opt/myapp/django-static/ 
RUN mkdir /opt/myapp/django-media/ 
RUN mkdir /opt/myapp/webroot/ 
run mkdir -p /opt/myapp-logs/nginx/ 
WORKDIR /opt/myapp/ 

# Copy configs and code to Container 
ADD config/nginx.conf /etc/nginx/nginx.conf 
ADD config/nginx-site.conf /etc/nginx/sites-enabled/nginx.conf 
ADD config/uwsgi_params /etc/nginx/uwsgi_params 

EXPOSE 80 
+0

404 nginx的建議沒有達到你的'server' nginx的配置塊;也許參數在默認的nginx配置文件覆蓋你的配置?你嘗試刪除它嗎?如果這沒有幫助,請發佈你的nginx/Dockerfile的內容。 – rafalmp

+0

nginx服務器在通過nginx容器ip訪問時提供uwsgi內容(通過'sudo docker檢查 | grep IPAddress'。 – user2693188

+0

獲取剛剛添加了我的nginx Dockerfile,我在考慮我是否在使用撰寫文件.. – user2693188

回答

1

默認網站Nginx的配置文件包括行:

server_name localhost; 

所以當你去http://localhost:9999此配置使用;另外 - nginx不處理/etc/nginx/sites-enabled目錄及其內容;從默認nginx.conf

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

修改您的Dockerfile - 而不是:

ADD config/nginx-site.conf /etc/nginx/sites-enabled/nginx.conf 

使用:

RUN rm /etc/nginx/conf.d/default.conf 
ADD config/nginx-site.conf /etc/nginx/conf.d/nginx.conf 
+0

太棒了,它的工作,非常感謝 – user2693188

相關問題