You probably would serve some website on your Debian server. Nginx will meet all your needs. Prerequisites:
- Debian 9
- a sudo non-root user (described in this article)
Step 1. Install Nginx
To install our HTTP server we will use command:
1
sudo apt-get install nginx
Allow 80 and 443 ports in the UFW:
1
sudo ufw allow 'WWW Full'
Step 2. Check our web server
In a web browser, enter http://<remot_server_ip>
and check it.
Or use curl
for that purpose:
1
curl <remot_server_ip>
Step 3. Manage the Nginx Process
To stop the web server:
1
sudo systemctl stop nginx
To start the web server when it is stopped:
1
sudo systemctl start nginx
To stop and then start the service again:
1
sudo systemctl restart nginx
If you are simply making configuration changes, Nginx can often reload without dropping connections:
1
sudo systemctl reload nginx
To make sure our web server will restart automatically when the server is rebooted, type:
1
sudo systemctl enable nginx
To test that this configuration works, restart server:
1
sudo shutdown -r now
After a minute or two, you may check that web server starts on reboot.
Server Root and Configuration
If you want to start serving your own pages or application through Nginx, you will want to know the locations of the Nginx configuration files and default server root directory.
Default Server Root
The default server root directory is /var/www/html
. Files that are placed in this directory will be served on your web server. This location is specified in the default server block configuration file that ships with Nginx, which is located at /etc/nginx/sites-enabled/default
.
Server Block Configuration
Any additional server blocks, known as Virtual Hosts in Apache, can be added by creating new configuration files in /etc/nginx/sites-available
.
To activate these configurations, create a symbolic link to /etc/nginx/sites-enabled, using the following:
1
sudo ln -s /etc/nginx/sites-available/site /etc/nginx/sites-enabled/site
All configuration files in the sites-enabled directory will be loaded by Nginx.
Nginx Global Configuration
The main Nginx configuration file is located at /etc/nginx/nginx.conf
. This is where you can change settings like the user that runs the Nginx daemon processes, and the number of worker processes that get spawned when Nginx is running, among other things.