The blog about containerisation, virtual machines and useful shell snippets and findings

How to expose internal website via nginx-proxy

For instance you have several small-sized dockerized websited on different servers in your internal network with webserver’s IP like 192.168.0.2, 192.168.0.3, 192.168.0.4 and you would like to expose your site to public via single IP address like 95.67.123.18.

Is that possible? Sure, and you can even use great jwilder/nginx-proxy image for that.

Just create on public webserver folder /home/user/conf.d/external.conf and put there config like this

log_format vhost '$host $remote_addr - $remote_user [$time_local] '
                 '"$request" $status $body_bytes_sent '
                 '"$http_referer" "$http_user_agent"';
upstream server.it-premium.com.ua {
  server 192.168.0.2:80;
}
server {
  server_name server.it-premium.com.ua;
  listen 80;
  location / {
    proxy_pass http://server.it-premium.com.ua;
  }
  access_log /var/log/nginx/access.log vhost;
}

also launch nginx-proxy container with extra arguments

-v /home/user/conf.d/external.conf:/etc/nginx/conf.d/external.conf

that will connect single config file to nginx config folder and will read configuration from there.
Beware, in case you change manually external.conf you’ll need to restart your nginx container, because docker will treat your file as invalid.