Nethence NEWDOC OLDDOC Lab Webmail Your IP BBDock  

setting up a reverse-proxy with NGINX

install

on Ubuntu,

    apt install nginx
    netstat -antpe --inet --inet6 | grep LISTEN | grep 80
service nginx status
#update-rc.d nginx defaults

    cp -pi /etc/nginx/sites-available/default /etc/nginx/sites-available/default.dist
    cp -pi /etc/nginx/nginx.conf /etc/nginx/nginx.conf.dist
    rm -f /var/www/html/index.nginx-debian.html
echo "<p>nothing here" > /var/www/html/index.html

on RHEL/CentOS, make sure the EPEL repo is available and proceed,

    yum install nginx
    netstat -antpe --inet --inet6 | grep LISTEN | grep 80
    service nginx start
    chkconfig nginx on

    cp -pi /etc/nginx/nginx.conf /etc/nginx/nginx.conf.dist
ls -alhF /usr/share/nginx/html/

tuning

enable directory listing,

index index.html index.php;
autoindex on;

and apply with service nginx restart

vhosts

setup a vhost,

    cd /etc/nginx/conf.d/
    vi host.example.com.conf

server {
    listen 80;
    listen [::]:80;

    server_name host.example.com;

    root /path/to/host.example.com;
    index index.html index.php;
    autoindex on;

    location / {
        try_files $uri $uri/ =404;
    }
}

auth

in the server stanza,

            location ^~ /private/ {
                    auth_basic "Restricted Area";
                    auth_basic_user_file htpasswd;
            }

then create or edit password file,

cd /etc/nginx/
#apt -y install apache2
#yum -y install httpd
htpasswd -c htpasswd NEWUSER
#DO NOT chmod 600 htpasswd
#if files exists already, htpasswd htpasswd NEWUSER
service nginx restart

Ref. http://nginxlibrary.com/password-protect-a-directory/

reverse

setup an http reverse proxy,

cd /etc/nginx/conf.d/
vi host2.example.com.conf

server {
 listen 80;
 server_name host2.example.com;

 location / {
   proxy_pass https://0.0.0.0:80XX;
   proxy_set_header X-Real-IP $remote_addr;
 }

}

service nginx restart

References