NGNIX Installation on a VPS

NGNIX Installation on a VPS

The NGINX(Pronounced “Engine X”) is a free, open-source HTTP web server and reverse proxy, as well as operates as an IMAP/POP3 mail proxy server and as a load balancer with HTTP cache server.

VPS9 Nov Blog1 - NGNIX Installation on a VPS

NGNIX installation on a Virtual Private Server (VPS)

Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet.

NGINX is known for its highly scalable,  performance, simple configuration, high stability, rich feature set,  resource-friendly, and low resource consumption. For these reasons, it is a great alternative to the more commonly used Apache webserver(third most popular Web server behind the Apache Server).

Today, we are going to discuss setting up and configuring NGNIX on a Virtual Private Server (VPS).

Prerequisites

  • A non-root user with Sudo privileges configured on your server.
  • SSH access to your VPS

How to install NGINX on VPS

1. Install NGINX

with the “yum” Package manager  using the following commands:

>>yum install epel-release>>yum install Nginx

 

2. Start NGINX

After installation, start the NGINX:

>>Systemctl start Nginx

 

3. Allow the Nginx

Check if HTTP and HTTPS ports are allowed by firewalls

>>firewall-cmd --list-all

Note: If TCP ports 80 and 443 are not listed, the allow them to the firewall using following commands

>>firewall-cmd --permanent --zone=public --add-port=80/tcp >>firewall-cmd --permanent --zone=public --add-port=443/tcp

 

4. Reload the firewall

>>firewall-cmd --reload

   

5. Test the NGINX

To test the installation you need to use your public IP address

    https://your_server_IP_address/

6. Configure the NGINX and Boot it

The main NGINX configuration file is located at

    >>/etc/Nginx/nginx.conf. >>systemctl enable Nginx

How to Restart Nginx

Test the Nginx configuration and restart Nginx:

>>sudo Nginx -t>>sudo systemctl restart Nginx

How to uninstall the Nginx

  1. If you want to keep config files and just want to remove the Nginx
>>sudo apt-get remove Nginx Nginx-common
  1. If you want completely uninstall the Nginx
>>sudo apt-get purge Nginx Nginx-common

That’s it! Now that you have your web server – NGINX installed successfully on a VPS!

Why Use Nginx on a VPS?

Nginx is a high-performance web server and reverse proxy known for low memory use and efficient handling of many concurrent connections. It is a popular choice for WordPress, Node.js and static-heavy sites on a VPS.

Before You Start

  • A VPS running Ubuntu, Debian or CentOS-based Linux with root or sudo access
  • A domain pointing to the server IP
  • Ports 80 and 443 open in the firewall

Install and Start Nginx

On Ubuntu or Debian, update the package list and install the nginx package with apt; on AlmaLinux or Rocky Linux use dnf. Then enable the service with systemctl enable –now nginx and open your server IP in a browser to confirm the welcome page loads.

Configure a Server Block

  1. Create a configuration file for your domain in the sites-available directory (or conf.d on RHEL-based systems).
  2. Set server_name to your domain and root to your site directory.
  3. Test with nginx -t, then reload using systemctl reload nginx.

Secure Nginx with SSL

Install Certbot and request a free Let’s Encrypt certificate for your domain; it can configure HTTPS and automatic renewal for you.

Performance and Security Tips

  • Enable gzip or Brotli compression and browser caching headers.
  • Hide the server version with server_tokens off.
  • Use a firewall (UFW or firewalld) and Fail2ban.
  • Keep Nginx updated.

FAQ

Nginx or Apache?

Nginx is lighter under heavy traffic; Apache offers wide .htaccess support. Many setups combine both.

Why do I get a 502 error?

Usually the backend (PHP-FPM or app server) is down or misconfigured. Check its service and the Nginx error log.