Install Nginx Web Server on Debian 11
How to install Nginx Web Server on Debian 11. Install Nginx and configure Uncomplicated Firewall (ufw). Create a simple test website and basic Nginx http server block.
Install Nginx Web Server
# update packages apt update && apt upgrade # install nginx apt install nginx # check nginx status systemctl status nginx
# check nginx version nginx -v
Configure Uncomplicated Firewall (ufw) for Nginx
# add ufw firewall rules to allow http and https ufw allow 80 ufw allow 443 # check ufw status ufw status
Reloading and restarting Nginx
#restart nginx service nginx restart #stop nginx service nginx stop #start nginx service nginx start #reload nginx service nginx reload
Whats the difference between restarting and reloading Nginx?
Checking Nginx Configuration
# check nginx config files nginx -t
Nginx user on Debian
The Nginx web server runs as user www-data on Debian
Nginx configuration files
/etc/nginx/nginx.conf
The default config file that Nginx reads when the web server starts
sites-available and sites-enabled/etc/nginx/sites-available
/etc/nginx/sites-enabled
sites-available contains all the website config files, sites-enabled contains live websites that are running on the web server
Web sites are enabled by creating a symbolic link to the config file in /etc/nginx/sites-enabled
sudo ln -s /etc/nginx/sites-available/yourdomain.com.conf /etc/nginx/sites-enabled/
Create simple website for testing
Website root directory, public HTML folder 750
Website directories 755
Website files 644
PHP configuration files 444
Create website folders
mkdir /var/www/yourdomain.com/html -p
Change owner and group to nginx user
chown -Rf www-data:www-data /var/www/yourdomain.com
Change folder permissions
chmod -Rf 750 /var/www/yourdomain.com
Create a test index.html page for the new site
nano /var/www/yourdomain.com/html/index.html
<html> <head> <title>Welcome to Your Domain </title> </head> <body> <h1>Nginx web server has been setup for yourdomain.com </h1> <p>This is a test page.</p> </body> </html>
Create basic Nginx http server block
nano /etc/nginx/sites-available/yourdomain.com.conf
server { listen 80; root /var/www/yourdomain.com/html; index index.html; server_name yourdomain.com; }
Link the web site config file to sites-enabledsudo ln -s /etc/nginx/sites-available/yourdomain.com.conf /etc/nginx/sites-enabled
Test the nginx confignginx -t
Reload nginxservice nginx reload
Example: Windows hosts file
C:\Windows\System32\drivers\etc\hosts
References:
by Author
Controlling NGINX Processes at Runtime
Nginx Beginners Guide
Comments