docker-nginx-auto-ssl
docker-nginx-auto-ssl copied to clipboard
How to config backend and frontend with same domain
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 Did you find a solution to this issue?
@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:
- Add support for this in
entrypoint.sh
, whereSITES
variable is parsed and configuration files prepared - 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
- Instead of using
yourdomain.com:8080
use subdomain, likesubdomain.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 fromsubdomain.yourdomain.com
to your server IP address.