2017-06-05 32 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

相关问题