多Docker容器的Nginx
我想为不同的docker容器实现不同的端口。如果请求到8080端口,则应转到nginx容器等 我的docker编写文件多Docker容器的Nginx,docker,nginx,docker-compose,load-balancing,nginx-reverse-proxy,Docker,Nginx,Docker Compose,Load Balancing,Nginx Reverse Proxy,我想为不同的docker容器实现不同的端口。如果请求到8080端口,则应转到nginx容器等 我的docker编写文件 version: "3" services: ngnix: image: nginx ports: - "8080:80" volumes: - ./nginx.conf/:/etc/nginx/nginx.conf command: [nginx-debug, "-g", "daemon off;"] apac
version: "3"
services:
ngnix:
image: nginx
ports:
- "8080:80"
volumes:
- ./nginx.conf/:/etc/nginx/nginx.conf
command: [nginx-debug, "-g", "daemon off;"]
apache:
image: httpd
command: bash -c "httpd -D FOREGROUND"
ports:
- "8081:80"
我的nginx.conf文件如下:
worker_processes 1;
events { worker_connections 1024; }
http {
sendfile on;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
server {
listen 8080;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
}
}
server {
listen 8081;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:8081;
proxy_redirect off;
}
}
}
但它不起作用。我把所有时间都花在哪里了?Docker 127.0.0.1中始终是“这个容器”。Docker文档(如)描述了Docker Compose设置中的一般网络环境,以及如何从一个容器调用另一个容器。我不能使用nginx吗?您的nginx没有监听端口8081,所以
http://127.0.0.1:8081
到达此容器中的8081端口是行不通的。您并没有真正利用Docker网络,而是以需要在主机上公开应用的方式代理您的请求。不要这样做,您应该将nginx和应用程序放在同一个Docker网络中,这样就可以在容器内而不是容器外访问它们。看看。我想,如果我写docker compose,它会工作。但是jwilder/nginx代理必须手动执行。Docker127.0.0.1始终是“这个容器”。Docker文档(如)描述了Docker Compose设置中的一般网络环境,以及如何从一个容器调用另一个容器。我不能使用nginx吗?您的nginx没有监听端口8081,所以http://127.0.0.1:8081
到达此容器中的8081端口是行不通的。您并没有真正利用Docker网络,而是以需要在主机上公开应用的方式代理您的请求。不要这样做,您应该将nginx和应用程序放在同一个Docker网络中,这样就可以在容器内而不是容器外访问它们。看看。我想,如果我写docker compose,它会工作。但是jwilder/nginx代理必须手动执行