Saturday, February 3, 2018

Nginx - Reverse Proxy

Proxy server

server {
    listen       80;
    server_name  proxy.com;

    location / {
        auth_basic "Restricted Content";
        auth_basic_user_file /etc/nginx/.htpasswd;
        proxy_pass https://destination.com;
    }
}

Load balancing

http {
    upstream myapp1 {
        server srv1.example.com;
        server srv2.example.com;
        server srv3.example.com;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://myapp1;
        }
    }
}