我想将我的Web应用程序容器化。目前,我正在使用Apache来提供几个PHP应用程序。
每个应用程序都应该由自己的容器提供。 Nginx应该可以通过80/443端口访问。根据子路由的不同,它应该代理到其中一个容器。
例如:
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卷中的行,则可以正常工作。
我做错了什么吗?http:// was missing. But proxying still not working on subroutes. Only location / is working. How I get /hell1 running?