How To: Install nginx server & enable TLS Support
- Chris Speed 
- Jan 3, 2023
- 2 min read
Updated: Jul 21, 2023

sudo apt update
sudo apt install nginxSetting up Virtual Host
cd /etc/nginx/sites-enabled
sudo "${EDITOR:-vi}" tutorialserver {
       listen 81;
       listen [::]:81;
       server_name example.ubuntu.com;
       root /var/www/tutorial;
       index index.html;
       location / {
               try_files $uri $uri/ =404;
       }
}Restart nginx
In some cases this error is caused by a default Nginx site already on port 80. Removing default config works if you don't need a default one!
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
1. Update the system packages by running the following command:
sudo yum update2. Install the EPEL repository, which provides additional packages, using the following command:
sudo yum install epel-release3. Once the EPEL repository is installed, you can proceed to install Nginx by running the following command:
sudo yum install nginx4. After the installation completes, start the Nginx service using the following command:
sudo systemctl start nginx5. To enable Nginx to start automatically at system boot, run the following command:
sudo systemctl enable nginx6. Open firewall port
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload7. Open http//:<ip address>/ or http://10.0.0.92/
Enable an Nginx server with TLS (Transport Layer Security) Support
1. Self-signed certificate (for testing/development purposes): If you want to create a self-signed certificate, you can use OpenSSL to generate it. Run the following command to generate a self-signed certificate and private key:
cd /etc/nginx
sudo mkdir ssl
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/server.key -out /etc/nginx/ssl/server.crt2. Configure Nginx for TLS: Open the Nginx configuration file for your server using a text editor. The default configuration file is located at `/etc/nginx/nginx.conf`, but you can create a separate configuration file for your TLS server if needed.
   sudo nano /etc/nginx/nginx.conf3. Inside the configuration file, locate the `server` block that corresponds to your website or create a new one. Within the `server` block, add the following lines to configure TLS:
   server {
       listen 443 ssl;
       server_name your-domain.com;
       ssl_certificate /etc/nginx/ssl/server.crt;
       ssl_certificate_key /etc/nginx/ssl/server.key;
       # Additional TLS configurations (optional)
       ssl_protocols TLSv1.2 TLSv1.3;
       ssl_ciphers HIGH:!aNULL:!MD5;
       # ... other server configurations
   }Replace `your-domain.com` with the actual domain name or IP address of your server. Make sure to specify the correct paths to your SSL certificate (`ssl_certificate`) and private key (`ssl_certificate_key`).
4. Test Nginx configuration:
   sudo nginx -t7. Restart Nginx:
   sudo systemctl restart nginxReferences:

Comments