2017-06-05 60 views
0

我目前正在創建使用泊塢窗將接受從Web代理服務器的請求的NGINX反向代理服務器將請求發送到網站時,然後重定向向我想要在線的網站請求容器。所以我現在有2個容器,一個用於Nginx反向代理,另一個容器包含帶有LEMP和我的網站文件的Nginx。出於某種原因,我不斷收到502錯誤的網關錯誤。我已經單獨測試了網站容器(直接連接到網站而不是通過代理)並正確顯示了網站。另外,我使用'wget'來測試終端的連通性,並且網站容器可以正常連接,但是當試圖使用'wget'訪問Nginx代理容器時,它也會顯示502 Bad Gateway Error。我對web dev非常陌生,所以我很感激任何幫助,因爲我可能只是錯過了一些簡單的東西。錯誤創建於碼頭工人一個NGINX反向代理,並在另一個容器

Nginx的反向代理配置文件

server { 
    listen 80 default_server; 
    listen [::]:80 default_server; 

    # include snippets/snakeoil.conf; 

root /var/www/html; 

index index.html index.php index.htm index.nginx-debian.html; 

server_name 138.197.67.44; 

location/{ 
      # First attempt to serve request as file, then 
      # as directory, then fall back to displaying a 404. 
      try_files $uri $uri/ =404; 
      proxy_set_header X-Real-IP $remote_addr; 
      proxy_pass http://172.17.0.2:80; 
    } 
} 

DockerFile反向代理

############################################################# 
#Dockerfile for creating and configuring a Nginx Reverse Proxy 
#Based in Ubuntu 16.04 
############################################################## 


#Set base image as existing image with nginx configuration (one shown above) 
FROM nginxproxyr 

#FileName + Author 
MAINTAINER NginxProxy Javier 

# Update the repository sources lsit RUN apt-get update 
#NOTE EVERYTHING IS ALREADY INSTALLED IN BASE IMAGE USED; just required to  configure the image 

#EXPOSE AND ASSIGN PORTS 

#Expose default port 
EXPOSE 80 

#Give access to the system to reach the script that runs the entrypoint 
RUN chmod +x /usr/bin/startup.sh 

#Default port to excecute entrypoint 
CMD service nginx start 

命令當你有兩個容器運行從圖像通過Dockerfile

sudo docker run -it -p 80:80 -d NginxReverseProxy 
+0

從Nginx容器中查看日誌會很有用。 你如何啓動LEMP容器? –

+0

另外,你不應該依賴於LEMP容器的IP是不變的。這些內部IP可以在容器重新啓動時更改。 爲您簡單的測試,你可以使用已棄用[鏈接](https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/#connect-with-the-linking-system)功能。但要繼續投入時間來學習[網絡](https://docs.docker.com/engine/userguide/networking/work-with-networks/)功能。這是Docker Compose使用的。 –

回答

0

創建一個容器我建議您使用docker-compose並且不通過服務進行引用通過IP。現在,如果你想重定向,建議使用這個很簡單的圖片來看看它是如何工作的。

https://github.com/jwilder/nginx-proxy

+0

是的,這是我對未來的計劃,因爲我聽說docker撰寫的文章更有用。但是,我一直在這個錯誤上停留了很長時間,我真的很想弄清楚是什麼導致了這個錯誤。感謝你的迴應! – Javx123

+0

嘗試刪除de nginx sever名稱配置,也許你修復了錯誤。 – German

+0

不幸的是它沒有工作。謝謝你的迴應。 – Javx123

相關問題