<> = nginx = == Install on FreeBSD 10.3 == * pkg install nginx * /usr/local/etc/nginx/nginx.conf {{{ load_module /usr/local/libexec/nginx/ngx_mail_module.so; load_module /usr/local/libexec/nginx/ngx_stream_module.so; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /usr/local/www/nginx; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/local/www/nginx-dist; } } } include /usr/local/etc/nginx/sslbalance.d/*; }}} * /usr/local/etc/nginx/sslbalance.d/sslbalance.conf {{{ stream{ upstream backend { server 127.0.0.1:8443; server 127.0.0.1:8444; } server { listen 443; proxy_pass backend; } } }}} == Install on Slackware == {{{#!highlight bash cd /tmp wget https://slackbuilds.org/slackbuilds/14.2/network/nginx.tar.gz tar xvzf nginx.tar.gz cd nginx wget http://nginx.org/download/nginx-1.10.2.tar.gz ./nginx.SlackBuild installpkg /tmp/nginx-1.10.2-x86_64-1_SBo.tgz /etc/rc.d/rc.httpd stop sh /etc/rc.d/rc.nginx start }}} == nginx.conf with reverse proxy example == {{{ # nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 80; server_name localhost; location / { root /var/www/html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/html; } } server{ listen 80; server_name abc.example.org; location / { proxy_pass http://127.0.0.1:8081; } } server { listen 80; server_name cde.example.org; location / { proxy_pass http://127.0.0.1:8082; } } } }}} == Reverse proxy with redirect from 80 t0 443 == {{{ cat /etc/nginx/sites-enabled/example.org server { listen 80; return 301 https://example.org$request_uri; server_name example.org; #root /var/www/example; location / { proxy_pass http://localhost:8888/; } } server { listen 443 ssl; server_name example.org; location / { proxy_pass http://localhost:8888/; } ssl_certificate /etc/ssl/certs/example_fullchain.crt; ssl_certificate_key /etc/ssl/private/example_private.key; } }}} == test.example.org == {{{#!highlight sh # SSL/TLS cert sudo bash mkdir -p /var/www/test.example.org/ echo "Hello test" > /var/www/test.example.org/index.html # create getssl configuration files and folder for test.example.org ./getssl -c test.example.org # edit config file nano ~/.getssl/test.example.org/getssl.cfg }}} {{{#!highlight sh # specify correct ACL option CA="https://acme-v02.api.letsencrypt.org" ACL=('/var/www/test.example.org/.well-known/acme-challenge') }}} {{{#!highlight sh nano /etc/nginx/sites-enabled/test.example.org | grep -v "#" }}} {{{#!highlight sh server { listen 80; server_name test.example.org; root /var/www/test.example.org; } }}} {{{#!highlight sh ./getssl test.example.org #Certificate saved in /root/.getssl/test.example.org/test.example.org.crt cp /root/.getssl/test.example.org/fullchain.crt /etc/ssl/certs/test_fullchain.crt cp /root/.getssl/test.example.org/test.example.org.key /etc/ssl/private/test_private.key nano /etc/nginx/sites-enabled/test.example.org | grep -v "#" }}} {{{#!highlight sh server { listen 80; return 301 https://test.example.org$request_uri; server_name test.example.org; root /var/www/test.example.org; } server { listen 443 ssl; server_name test.example.org; root /var/www/test.example.org; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers on; ssl_certificate /etc/ssl/certs/test_fullchain.crt; ssl_certificate_key /etc/ssl/private/test_private.key; } }}} {{{#!highlight sh curl -s https://test.example.org/ -vvv 2>&1 | grep -e "expire date" -e Host #* Host test.example.org:443 was resolved. #* expire date: Sep 10 12:31:58 2026 GMT #> Host: test.example.org cd /var/www/ chown www-data * -R chgrp www-data * -R nginx -t service nginx restart }}}