Nginx

Nginx guides
Install Nginx
Nginx.conf
PHP-FastCGI on Windows Nginx

Install

On Debian and Ubuntu Nginx installs from the distribution repositories:

sudo apt update

sudo apt install nginx

The installer starts the service right away. Check that it answers:

curl -I http://localhost/

The expected first line of the answer is from Nginx:

HTTP/1.1 200 OK

Configuration files

The main configuration file is /etc/nginx/nginx.conf. Site configurations live in /etc/nginx/sites-enabled/ and the default site serves files from /var/www/html/. After every configuration change test it first and reload only when the test passes:

sudo nginx -t

sudo systemctl reload nginx

First server block

A minimal site answering on port 80 looks like this. Save it as /etc/nginx/sites-enabled/example.com:

server { listen 80; server_name example.com; root /var/www/example.com; index index.html; }

Reverse proxy

To forward visitors to an application on another port, proxy the requests instead of serving files:

server { listen 80; server_name example.com; location / { proxy_pass http://127.0.0.1:8080; } }

Test the configuration and reload Nginx as shown above.

Article author: Andrei Olegovich