This describes how to set up and use nginx on Debian 10 Buster

Installation
Ensure your server is up to date with apt-get update && apt-get upgrade.
Install nginx with apt-get install nginx.
Recommended: Install ufw and allow ports 80 and 443 with ufw allow 80,443/tcp.
Ensure nginx is running with systemctl status nginx, there should be green text reading Active: active (running).
Your nginx server should now be set up.

Configuration
Creating new site configurations (The default configuration will serve from /var/www/html on any requests not matching other sites)
Create new site file with nano /etc/nginx/sites-available/site-name
Create directory for the site for example mkdir /var/www/homepage
Set up site for HTTP, paste in the following
server {
listen 80;
listen [::]:80;
root /path/to/root/directory;
index index.html index.htm index.php index.asp index.aspx;
server_name domain.com www.domain.com;
location / {
try_files $uri $uri/ = 404
}
}

Global nginx configuration
Open the configuration file with nano /etc/nginx/nginx.conf
Change any settings you may want to in this file, most commonly you may want to change logging locations access_log and error_log

Proxying
A proxy can be used to redirect a subdomain to another location without adding a new A record to your DNS
Create a file to store proxy configs in (this can be either one file or multiple) using nano /etc/nginx/conf.d/proxy.conf
Paste in a new server configuration (this example proxies requests to http://mail.domain.com to http://www.gmail.com)
server {
listen 80;
server mail.domain.com;
location / {
proxy_pass http://www.gmail.com;
}
}

Don't forget to restart nginx with systemctl restart nginx after any changes to the config
Was this article helpful?
Cancel
Thank you!