I have a dedicated server on which I want to host different sites, each running in a separate docker container. I don't have a domain, so I want to access the server by IP address or dynDNS URL. Each site should be available under a subfolder of my IPaddress / dyndns like so:
http://10.10.10.10/site-a --> redirects to e.g. nginx running in container A
http://10.10.10.10/site-b --> redirects to e.g. appache running in container B
etc.
I think I should use a reverse proxy for this. I found this one https://github.com/jwilder/nginx-proxy which seems to be pretty easy in terms of extendablility if I plan to add further container in future. However I always get a HTTP 503 Service Temporarily Unavailable if I try to access http://10.10.10.10/site-a or http://10.10.10.10/site-a or http://10.10.10.10 directly.
I tried the whoami example as described on https://github.com/jwilder/nginx-proxy#docker-compose This works perfectly if I try curl -H "Host: whoami.local" localhost
I modified this docker-compose.yml example to fit my use-case:
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
ports:
- "80:80"
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
site-a:
image: nginx
volumes:
- /home/chris/docker/site-a:/usr/share/nginx/html
environment:
- VIRTUAL_HOST=site-a.local
site-b:
image: nginx
volumes:
- /home/chris/docker/site-b:/usr/share/nginx/html
environment:
- VIRTUAL_HOST=site-b.local
Site-a and site-b are just nginx containers hosting a static html file for testing purpose.
Executing
curl -H "Host: site-a.local" http://10.10.10.10
returns the static html from site-a
curl -H "Host: site-b.local" http://my-dyn-dns.com
returns the static html from site-b
But if I try to access any of these URLs with the browser I get the HTTP 503 again :-(
the nginx.conf is untouched from the dockerhub image:
/etc/nginx# cat nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
daemon off;