nginx

Config snippets

Return a file on system.

location / {
	alias /var/www/html/index.html;
}

Return a same file using Nginx in single page application.

location / {
	try_files $uri $uri/ /index.html;
}

same as a single entry PHP application. :)


WebSocket Proxying

location /chat/ {
    proxy_pass <http://backend>;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

Automation proxy docker application

docker run --detach \\
    --name nginx-proxy \\
    --publish 80:80 \\
    --publish 443:443 \\
    --volume /etc/nginx/certs \\
    --volume /etc/nginx/vhost.d \\
    --volume /usr/share/nginx/html \\
    --volume /var/run/docker.sock:/tmp/docker.sock:ro \\
    jwilder/nginx-proxy:alpine

docker run --detach \\
    --name nginx-proxy-letsencrypt \\
    --volumes-from nginx-proxy \\
    --volume /var/run/docker.sock:/var/run/docker.sock:ro \\
    --env "DEFAULT_EMAIL=doudou19758@gmail.com" \\
    jrcs/letsencrypt-nginx-proxy-companion

# and set following 2 env for the app you want to proxy
# VIRTUAL_HOST
# LETSENCRYPT_HOST