// ssd vps

How to Install and Configure Nginx on a Linux VPS: Complete Guide for a High-Performance Web Server

September 16, 2026 · by Alex M.

How to Install and Configure Nginx on a Linux VPS: Complete Guide for a High-Performance Web Server

Nginx has become one of the most popular web servers in the world — and for good reason. Low memory consumption, the ability to handle thousands of simultaneous connections, and configuration flexibility make it the ideal choice for any SSD VPS or NVMe VPS. In this guide, you'll walk through the entire process step by step: from installation to configuring virtual hosts with HTTPS and performance optimization.

What Is Nginx and Why Should You Use It?

Nginx (pronounced "engine-x") is an open-source web server created by Igor Sysoev in 2004. Unlike Apache, which creates a new thread or process for each connection, Nginx uses an event-driven architecture — making it exceptionally efficient under high traffic loads.

Key advantages:
- Excellent performance under high concurrent traffic
- Low RAM and CPU consumption
- Native support for reverse proxy, load balancer, and HTTP cache
- Flexible configuration with clear syntax
- Active support and a large community

If you have a VPS with dedicated resources and want to run PHP, Node.js, Python applications, or serve static files at maximum speed, Nginx is the right choice.

Prerequisites

Before starting, make sure you have:
- A VPS running Ubuntu 22.04 / Debian 12 (this guide is compatible with both)
- Root access or a user with sudo privileges
- A domain configured to point to your server's IP address (for HTTPS setup)
- Ports 80 and 443 open in your firewall

If you don't have a server yet, you can quickly order an NVMe VPS from CLIQHOST with Ubuntu pre-installed and immediate SSH access.

Step 1: Update the System and Install Nginx

The first step is always updating the package list:

sudo apt update && sudo apt upgrade -y

Install Nginx:

sudo apt install nginx -y

Check the service status:

sudo systemctl status nginx

You should see active (running). If not, start the service manually:

sudo systemctl start nginx
sudo systemctl enable nginx

Verify the installed version:

nginx -v

Open http://YOUR_SERVER_IP in a browser — you'll see the default Nginx page confirming a successful installation.

Step 2: Understanding the Nginx Configuration File Structure

Before making any changes, understanding the directory structure is essential:

/etc/nginx/
├── nginx.conf          # Global configuration
├── sites-available/    # Available virtual host configurations
├── sites-enabled/      # Symbolic links to active configurations
├── conf.d/             # Additional configurations
├── snippets/           # Reusable configuration fragments
└── modules-enabled/    # Loaded modules

The main file /etc/nginx/nginx.conf contains global directives. Do not modify it directly for virtual hosts — create separate files in sites-available/.

Step 3: Configuring a Virtual Host (Server Block)

A "server block" in Nginx is the equivalent of Apache's VirtualHost. It allows serving multiple websites from the same server.

Create a directory for your site:

sudo mkdir -p /var/www/example.com/html
sudo chown -R $USER:$USER /var/www/example.com/html
sudo chmod -R 755 /var/www/example.com

Create a test page:

nano /var/www/example.com/html/index.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Welcome to example.com!</title>
</head>
<body>
    <h1>Nginx is working correctly!</h1>
</body>
</html>

Create the site's configuration file:

sudo nano /etc/nginx/sites-available/example.com
server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;
    root /var/www/example.com/html;
    index index.html index.htm index.php;

    location / {
        try_files $uri $uri/ =404;
    }

    # Dedicated logs per site
    access_log /var/log/nginx/example.com.access.log;
    error_log  /var/log/nginx/example.com.error.log;
}

Activate the site by creating a symbolic link:

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/

Test the configuration syntax:

sudo nginx -t

If everything is OK, reload Nginx:

sudo systemctl reload nginx

Step 4: Setting Up HTTPS with Let's Encrypt (Certbot)

In 2025, a website without HTTPS is unacceptable from both an SEO and security standpoint. Certbot completely automates obtaining and renewing free SSL certificates from Let's Encrypt.

Install Certbot and the Nginx plugin:

sudo apt install certbot python3-certbot-nginx -y

Obtain the SSL certificate:

sudo certbot --nginx -d example.com -d www.example.com

Certbot will ask for an email address and automatically modify the Nginx configuration to enable HTTPS and automatic redirects from HTTP to HTTPS.

Verify automatic renewal:

sudo systemctl status certbot.timer

Test renewal without actually issuing a certificate:

sudo certbot renew --dry-run

If you need a commercial certificate with OV or EV validation, CLIQHOST offers a full range of SSL certificates suited for online stores and business applications.

Step 5: Configuring Nginx for PHP Applications (PHP-FPM)

Nginx does not process PHP natively — it needs PHP-FPM (FastCGI Process Manager).

Install PHP-FPM:

sudo apt install php8.2-fpm php8.2-mysql php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml -y

Modify the server block to handle PHP files:

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com/html;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

This configuration is perfect for WordPress, Joomla, or any PHP application. If you prefer a ready-made solution for WordPress, explore our WordPress hosting plans with Nginx pre-configured.

Step 6: Optimizing Nginx Performance

Default Nginx settings are decent, but you can significantly improve them for a dedicated VPS.

Adjusting Worker Processes and Connections

Open /etc/nginx/nginx.conf and modify:

worker_processes auto;  # Automatically detects the number of CPUs

events {
    worker_connections 1024;  # Connections per worker (increase to 2048+ for high-traffic servers)
    use epoll;                # Most efficient I/O multiplexer on Linux
    multi_accept on;          # Accept multiple connections simultaneously
}

Enabling Gzip Compression

http {
    gzip on;
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_min_length 1000;
    gzip_types
        text/plain
        text/css
        text/javascript
        application/json
        application/javascript
        application/xml
        image/svg+xml;
}

Caching Static Files

location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2|svg)$ {
    expires 30d;
    add_header Cache-Control "public, no-transform";
    access_log off;
}

Limiting Request Size (Security)

client_max_body_size 20M;
client_body_timeout 12;
client_header_timeout 12;
keepalive_timeout 15;
send_timeout 10;

Step 7: Securing Your Nginx Server

A web server exposed to the internet requires additional security measures.

Hiding the Nginx Version

In nginx.conf, inside the http {} block:

server_tokens off;

HTTP Security Headers

Add to your server block:

add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

Blocking Access to Sensitive Files

# Block hidden files (.htaccess, .env, etc.)
location ~ /\. {
    deny all;
    return 404;
}

# Block direct access to configuration files
location ~* \.(conf|log|bak|sql|zip)$ {
    deny all;
    return 404;
}

Rate Limiting Login Endpoints

Protect login endpoints from brute-force attacks:

http {
    limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
}

server {
    location /wp-login.php {
        limit_req zone=login burst=3 nodelay;
    }
}

Step 8: Essential Commands for Daily Administration

# Test configuration without restarting
sudo nginx -t

# Reload configuration (zero downtime)
sudo systemctl reload nginx

# Full service restart
sudo systemctl restart nginx

# View logs in real time
sudo tail -f /var/log/nginx/error.log
sudo tail -f /var/log/nginx/access.log

# Check which ports Nginx is listening on
sudo ss -tlnp | grep nginx

# List active sites
ls -la /etc/nginx/sites-enabled/

Step 9: Nginx as a Reverse Proxy

One of the most common uses of Nginx on a VPS is as a reverse proxy — forwarding HTTP requests to a locally running application (Node.js, Python, Go, etc.).

server {
    listen 80;
    server_name app.example.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_cache_bypass $http_upgrade;
    }
}

This setup is essential when running containerized applications. For more DevOps and server administration content, visit the CLIQHOST blog.

Quick Troubleshooting: Most Common Errors

Error Probable Cause Solution
502 Bad Gateway PHP-FPM is not running sudo systemctl restart php8.2-fpm
403 Forbidden Wrong file permissions sudo chmod -R 755 /var/www/site/
nginx: [emerg] bind() to 0.0.0.0:80 failed Port 80 is occupied by another process sudo lsof -i :80 and stop the process
504 Gateway Timeout Backend application not responding in time Increase proxy_read_timeout
Configuration not applied Forgot nginx -t and reload Always test and reload after changes

Conclusion

Nginx is a robust, efficient, and flexible production web server — suitable for small websites and high-traffic enterprise applications alike. With the configurations in this guide, you have a solid foundation: multiple virtual hosts, automatic HTTPS, PHP support, basic security, and performance optimization.

For best results, Nginx shines brightest on SSD or NVMe infrastructure. If you want maximum speed without the hassle of server management, the CLIQHOST team offers both SSD VPS and NVMe VPS with full root access, as well as server management services if you'd rather focus on your application.

Have questions or need assistance configuring your server? Contact the CLIQHOST team — we're here to help.

SHARE
// what clients say

What Our Clients Say

Real reviews from customers who trust CLIQHOST for performance, reliability and expert technical support.

★★★★★

"We moved our online shop from a foreign host and the difference is night and day — pages load instantly and support replies in minutes, in Romanian."

AM
Andrei M.
eCommerce owner · Chișinău
★★★★★

"Migrated 12 client sites to CLIQHOST. Free migration, zero downtime, and the cPanel setup is exactly what my team needed. Highly recommend."

EV
Elena V.
Web agency · Bălți
★★★★★

"Our NVMe VPS handles traffic spikes without a sweat. Full root, local datacenter, and billing in MDL — everything we wanted from a provider."

DC
Dmitri C.
SaaS founder · Chișinău