Quantcast
Viewing all articles
Browse latest Browse all 1529

How to setup local dev environment with docker compose and few web services that share common domain

I need to have locally setup docker compose with 3 services that are map to subdomains, f.e.:

  • nginx.app.com
  • service1.app.com
  • service2.app.com
  • service3.app.com

It is important to share common domain like *app.com, cause I need this setup for JSESSION cookie testing.

Is such configuration feasible to achieve with docker compose and nginx docker service.

I have already docker-compose.yaml:

version: '3.8'services:  nginx:    image: nginx:latest    ports:      - "80:80"      - "443:443"    volumes:      - ./nginx/nginx.conf:/etc/nginx/nginx.conf      - ./nginx/ssl:/etc/nginx/ssl      - ./nginx/generate-certs.sh:/usr/local/bin/generate-certs.sh    entrypoint: /bin/bash -c "/usr/local/bin/generate-certs.sh && nginx -g 'daemon off;'"    depends_on:      - service1      - service2      - service3  service1:    image: nginx:latest    ports:      - "8081:80"    volumes:      - ./html:/usr/share/nginx/html  service2:    image: nginx:latest    ports:      - "8082:80"    volumes:      - ./html2:/usr/share/nginx/html  service3:    image: nginx:latest    ports:      - "8083:80"    volumes:      - ./html3:/usr/share/nginx/html

and nginx.conf:

events {}http {    upstream service1 {        server service1:80;    }    upstream service2 {        server service2:80;    }    upstream service3 {        server service3:80;    }    server {        listen 80;        server_name *.app.com;        location / {            return 301 https://$host$request_uri;        }    }    server {        listen 443 ssl;        server_name service3.app.com;        ssl_certificate /etc/nginx/ssl/nginx.crt;        ssl_certificate_key /etc/nginx/ssl/nginx.key;        location / {            proxy_pass http://service3;            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-Proto $scheme;        }    }    server {        listen 443 ssl;        server_name service1.app.com;        ssl_certificate /etc/nginx/ssl/nginx.crt;        ssl_certificate_key /etc/nginx/ssl/nginx.key;        location /1 {            proxy_pass http://service1;            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-Proto $scheme;        }    }    server {        listen 443 ssl;        server_name service2.app.com;        ssl_certificate /etc/nginx/ssl/nginx.crt;        ssl_certificate_key /etc/nginx/ssl/nginx.key;        location /2 {            proxy_pass http://service2;            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-Proto $scheme;        }    }    server {        listen 443 ssl;        server_name service3.app.com;        ssl_certificate /etc/nginx/ssl/nginx.crt;        ssl_certificate_key /etc/nginx/ssl/nginx.key;        location /3 {            proxy_pass http://service3;            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-Proto $scheme;        }    }}

whenever I access https://app.com it serves me well (I've added this host to /etc/hosts)but I can not reach https://service3.app.com from host - my pc browser

To sum up, I need this kind of architecture:Image may be NSFW.
Clik here to view.
enter image description here
https://blog.florianlopes.io/host-multiple-websites-on-single-host-docker/

please point me what I am doing wrong.


Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>