One of many uses of NGINX is http/https proxy load balancing. This guide is Debian specific so your milage with other flavors may vary. In this example we always redirect http to https.
The main nginx configation file is /etc/nginx/nginx.conf and below is a sample configuration file:
user www-data;
worker_processes 5;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;
#gzip on;
upstream lb2 {
server 10.0.0.10; #webserver10
server 10.0.0.20; #webserver20
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
To add a site:
Prepare SSL
Create a .pem file which contains the certificate, certificate signing request and private key in the following format(certificate request section optional):
Check if nginx process has started and is listening on configured IP:
12345
netstat -alnp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.1.1:80 0.0.0.0:* LISTEN 9593/nginx
tcp 0 0 192.168.1.1:443 0.0.0.0:* LISTEN 9593/nginx