top of page

How To: Install nginx server & enable TLS Support

Updated: Jul 21, 2023



sudo apt update
sudo apt install nginx

Setting up Virtual Host

cd /etc/nginx/sites-enabled
sudo "${EDITOR:-vi}" tutorial
server {
       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 update

2. Install the EPEL repository, which provides additional packages, using the following command:

sudo yum install epel-release

3. Once the EPEL repository is installed, you can proceed to install Nginx by running the following command:

sudo yum install nginx

4. After the installation completes, start the Nginx service using the following command:

sudo systemctl start nginx

5. To enable Nginx to start automatically at system boot, run the following command:

sudo systemctl enable nginx

6. Open firewall port

sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload

7. 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.crt

2. 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.conf

3. 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 -t

7. Restart Nginx:

   sudo systemctl restart nginx

References:


Recent Posts

See All
How to Samba on Ubuntu Server

Install sudo apt install samba -y Verfiy Installation systemctl status smbd Configure sudo nano /etc/samba/smb.conf Create symbolic to...

 
 
 

Comments


Contact Me

Tel: 678-642-8051

cspeed@jcsassoc.com

  • Google+ Long Shadow
  • LinkedIn Long Shadow
  • Facebook Social Icon
  • Twitter Long Shadow

© 2005 by Christopher Speed

Your details were sent successfully!

bottom of page