【发布时间】:2019-07-01 10:36:46
【问题描述】:
我想将我的 Web 应用程序容器化。目前,我正在使用 Apache 来提供几个 PHP 应用程序。
每个应用都应该由它们自己的容器提供。 端口 80/443 应该可以访问 Nginx。根据子路由,它应该代理到其中一个容器。
例如:
www.url.de/hello1 --> hello1:80
www.url.de/hello2 --> hello2:80
docker-compose.yml:
version: '3'
services:
nginx:
image: nginx:latest
container_name: reverse_proxy
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
ports:
- "80:80"
- "443:443"
networks:
- app-network
depends_on:
- hello1
- hello2
hello1:
build: ./test1
image: hello1
container_name: hello1
expose:
- "80"
networks:
- app-network
hello2:
build: ./test2
image: hello2
container_name: hello2
expose:
- "80"
networks:
- app-network
networks:
app-network:
nginx.conf:
events {
}
http {
error_log /etc/nginx/error_log.log warn;
client_max_body_size 20m;
proxy_cache_path /etc/nginx/cache keys_zone=one:500m max_size=1000m;
server {
server_name wudio.de;
location / {
proxy_pass http://hello1:80;
}
location /hello1/ {
proxy_pass http://hello1:80;
rewrite ^/hello1(.*)$ $1 break;
}
location /hello2/ {
proxy_pass http://hello2:80;
rewrite ^/hello2(.*)$ $1 break;
}
}
}
如果我运行 docker-compose up -d,只有图像 webapp-test1 的容器在线。我也可以通过curl localhost:8081 联系到它。
Nginx 没有运行。如果我删除将 nginx.conf 添加到 Nginx 卷中的行,它可以工作。
我做错了什么?
编辑1:
http:// was missing. But proxying still not working on subroutes. Only location / is working. How I get /hell1 running?
【问题讨论】:
-
您是否有错误消息、堆栈跟踪或类似内容?
-
很遗憾没有。该进程正在运行,没有任何错误/堆栈跟踪。看起来一切正常。但是 Nginx 不在线。如果我删除卷,它可以工作并且 Nginx 至少可以通过端口 80 访问
-
运行
docker logs nginx_container_id显示 nginx 容器的错误日志 -
@RajeshGupta 不是我,
-
尝试给出你试图映射的 nginx.conf 文件的完整路径,而不是相对路径。我有一个运行类似于您要求的 nginx 容器
标签: docker nginx docker-compose