我目前正在创建使用泊坞窗将接受从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
从Nginx容器中查看日志会很有用。 你如何启动LEMP容器? –
另外,你不应该依赖于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使用的。 –