Nginx

Contents
Install
Configuration files
First server block
Reverse proxy
Related articles
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.

Banner image

Article author: Andrei Olegovich

Related articles:
Nginx.conf
Установка Nginx
PHP-FastCGI on Windows Nginx

Search this site

Subscribe to Telegram channel @aofeed to follow new articles and updates to old ones

Go to channel

@aofeed

Ask a question in the Telegram group

@aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: