Quiero contenerizar mis aplicaciones web. Actualmente, estoy usando Apache para proporcionar un par de aplicaciones PHP .
Cada aplicación debe ser proporcionada por su propio contenedor. Se debe poder acceder a Nginx a través del puerto 80/443 . Dependiendo de la ruta secundaria, debería enviarse a uno de los contenedores.
Por ejemplo:
www.url.de/hello1 --> hello1:80 www.url.de/hello2 --> hello2:80docker-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; } } } Si ejecuto docker-compose up -d , solo el contenedor con la imagen webapp-test1 está en línea. Y también puedo alcanzarlo mediante curl localhost:8081 . Nginx no se está ejecutando. Si elimino la línea en la que agrego nginx.conf al volumen de Nginx, está funcionando. ¿Qué estoy haciendo mal?
Edit1:
http:// was missing. But proxying still not working on subroutes. Only location / is working. How I get /hell1 running?Tenga en cuenta la declaración proxy_pass. Tienes que mencionar el protocolo en esa declaración. También tenga en cuenta cómo puede hacer referencia al nombre del servicio en su archivo docker-compose.yml (en este caso hello1).
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 { listen 80; location / { try_files $uri @proxy ; } location @proxy { proxy_pass http://hello1:80/; } } }Editar: prueba esto en su lugar
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 { listen 80; location / { try_files $uri @proxy ; } location @proxy { if ($request_uri ~* "^\/hello1(\/.*)$") { set $url "http://hello1:80$1"; } if ($request_uri ~* "^\/hello2(\/.*)$") { set $url "http://hello2:80$1"; } proxy_pass "$url" } } }