docker-nginx-auto-ssl icon indicating copy to clipboard operation
docker-nginx-auto-ssl copied to clipboard

How to config backend and frontend with same domain

Open bugb opened this issue 4 years ago • 2 comments

This is an example from README:

version: '2'
services:
  nginx:
    image: valian/docker-nginx-auto-ssl
    restart: on-failure
    ports:
      - 80:80
      - 443:443
    volumes:
      - ssl_data:/etc/resty-auto-ssl
    environment:
      ALLOWED_DOMAINS: 'yourdomain.com'
      SITES: 'yourdomain.com=myapp:80'
  
  # your application, listening on port specified in `SITES` env variable
  myapp:
    image: nginx

volumes:
  ssl_data:

Here I can see yourdomain.com=myapp:80 will map yourdomain to frontend container my app (port 80), now if I want to use backend container with the same server, how can I make it works?

I have tried but it seems not work:

version: '2'
services:
  nginx:
    image: valian/docker-nginx-auto-ssl
    restart: on-failure
    ports:
      - 80:80
      - 443:443
    volumes:
      - ssl_data:/etc/resty-auto-ssl
    environment:
      ALLOWED_DOMAINS: 'yourdomain.com'
      SITES: 'yourdomain.com=myapp:80; yourdomain.com:8080=mybackendapp:8080'
  
  # your application, listening on port specified in `SITES` env variable
  myapp:
    image: nginx

  mybackendapp:
     image: myimage


volumes:
  ssl_data:

bugb avatar Dec 31 '20 03:12 bugb

@bugb Did you find a solution to this issue?

dryleaf avatar Apr 03 '22 06:04 dryleaf

@bugb @dryleaf This won't currently work. SITES is supposed to look like this domain1=container:port;domain2=container:port. There is no option for port next to the domain, like domain1:port=container:port.

There are three solutions:

  1. Add support for this in entrypoint.sh, where SITES variable is parsed and configuration files prepared
  2. Configure it by writing own configurtation file - should be simple, an example is here https://github.com/Valian/docker-nginx-auto-ssl#includes-from-etcnginxconfdconf
  3. Instead of using yourdomain.com:8080 use subdomain, like subdomain.yourdomain.com. It's probably the easiest and most elegant solution since it won't require typing :8080 port in the URL. To support this, there should be A record in DNS pointing from subdomain.yourdomain.com to your server IP address.

Valian avatar Apr 14 '22 11:04 Valian