9/6/2016 - 7:19 AM

nginx upstream backend

nginx upstream backend

# place this file under upstreams/ as myapp1-upstreams.conf
server localhost:8001;
server localhost:8002;
# server localhost:8003;
events {
  worker_connections  4096;  ## Default: 1024

daemon off;
pid ./nginx.pid;
error_log ./error.log;

http {
    upstream myapp1 {
        include upstreams/myapp1-upstreams.conf;
    server {
        listen 8000;
        location / {
            proxy_pass http://myapp1;

Python 2.7

python -m SimpleHTTPServer

Python 3.x

python -m http.server

Terminal 1

python -m http.server 8001

Terminal 2

python -m http.server 8002

Terminal 3

python -m http.server 8003

Terminal 4

/usr/sbin/nginx -c $(pwd)/nginx-lb.conf

Terminal 5 - send requests

curl -v http://localhost:8000

update myapp1-upstreams.conf (uncomment server 8003)

Terminal 5 - reload config

/usr/sbin/nginx -c $(pwd)/nginx-lb.conf -s reload

Terminal 5 - send requests

curl -v http://localhost:8000

$ nginx -h
nginx version: nginx/1.10.0 (Ubuntu) Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/share/nginx/) -c filename : set configuration file (default: /etc/nginx/nginx.conf) -g directives : set global directives out of configuration file

List configured modules

$ nginx -V
nginx version: nginx/1.10.0 (Ubuntu) built with OpenSSL 1.0.2g-fips 1 Mar 2016 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads

Config template


Reload config

/usr/sbin/nginx -s reload