So, you've rented a Virtual Private Server (VPS). Congratulations! You now have a powerful slice of the internet all to yourself. But right now, it's likely just a bare operating system—like a house with a foundation but no doors or windows. To get your website online, you need a web server. The best in the business? Nginx (pronounced "engine-x").
Nginx is a high-performance web server that handles thousands of connections simultaneously without breaking a sweat. It's lightweight, incredibly efficient at serving static files (like images, CSS, and JavaScript), and can also act as a reverse proxy and load balancer [citation:3][citation:4]. Companies like Netflix and Dropbox use it, which means it's more than capable of handling your blog or business site [citation:4].
In this guide, I'll walk you through installing and configuring Nginx on a Linux VPS (specifically Ubuntu, the most beginner-friendly distribution). We'll go from a fresh server to a live website with your own custom HTML page. Let's get started.
yum instead of apt) [citation:3].
First, open your terminal and connect to your server. Replace your_server_ip with your actual VPS IP address.
ssh root@your_server_ip
If you set up a different user (which is a good security practice), use that username instead of 'root'. Once logged in, you'll be at the command line, ready to work [citation:3].
Installing Nginx on Ubuntu is surprisingly simple. We'll use the apt package manager.
First, update your package list to make sure you're downloading the latest version:
sudo apt update
Now, install Nginx:
sudo apt install nginx -y
That's it! Nginx is now installed. The -y flag automatically confirms the installation prompt [citation:1][citation:10].
Before we can see our server, we need to tell the firewall to allow web traffic. If you're using Ubuntu's Uncomplicated Firewall (UFW), Nginx comes with a few pre-configured profiles.
Check which applications are registered with UFW:
sudo ufw app list
You should see outputs like 'Nginx HTTP', 'Nginx HTTPS', and 'Nginx Full'. We'll enable both HTTP (port 80) and HTTPS (port 443) by allowing the 'Nginx Full' profile [citation:1].
sudo ufw allow 'Nginx Full'
Now, verify the change:
sudo ufw status
You should see 'Nginx Full' listed as ALLOWED.
Nginx should have started automatically after installation. Let's verify that it's running correctly.
sudo systemctl status nginx
You should see an output that says active (running) in green [citation:4][citation:6].
The ultimate test is to see it in a browser. Open your favorite web browser and type in your server's public IP address (e.g., http://100.200.300.400). You should be greeted with the default "Welcome to nginx!" page [citation:1].
Can't see the page? Double-check your firewall settings (Step 3) and make sure your VPS provider's firewall/security group also allows traffic on ports 80 and 443 [citation:3][citation:7].
The default page is nice, but we want our own site. Nginx serves files from the /var/www/html/ directory by default [citation:6][citation:10]. However, it's better practice to create a separate directory for your domain. Let's create a simple folder and a test page.
Create a new directory for your site (replace 'example.com' with your domain or a name you prefer):
sudo mkdir -p /var/www/example.com/html
Assign ownership to your user (replace 'your_username' with your sudo username, or use the $USER variable if you're logged in as a non-root user):
sudo chown -R $USER:$USER /var/www/example.com/html
Now, let's create a simple index.html file to prove our setup works [citation:10].
nano /var/www/example.com/html/index.html
Paste in some simple HTML:
<html>
<head>
<title>My Awesome VPS Site</title>
</head>
<body>
<h1>Success! Nginx is working.</h1>
<p>My VPS is now serving my own custom page.</p>
</body>
</html>
Save the file (Ctrl+X, then Y, then Enter).
To tell Nginx to serve our new site, we need to create a server block (similar to Apache's virtual hosts).
Nginx keeps its configuration files in /etc/nginx/. The main places to look are [citation:4][citation:6]:
/etc/nginx/sites-available/: Where you store configuration files for each site./etc/nginx/sites-enabled/: Where you place symbolic links to the configs you want to actually run.
Create a new configuration file for your site in the 'sites-available' directory:
sudo nano /etc/nginx/sites-available/example.com
Add the following configuration. This tells Nginx to listen on port 80 for your domain and to serve files from the directory we created [citation:3][citation:10].
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
Save and exit the file.
Now, activate this configuration by creating a symbolic link to the 'sites-enabled' directory:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Always test your configuration for syntax errors before reloading. A simple mistake can break your site [citation:4].
sudo nginx -t
If you see "test is successful," you're good to go. Now, reload Nginx to apply the changes:
sudo systemctl reload nginx
Visit your server's IP address (or your domain, if it's pointed there) in your browser. You should now see your custom "Success! Nginx is working" page!
Congratulations! You've successfully installed Nginx on your VPS and configured it to serve a custom website. You've moved from a blank server to hosting your own content on the web. This is a huge step.
Next Steps & Final Checklist [citation:4]:
gzip on; to your Nginx config to make your site load faster.server_tokens off; to your config for a small security boost.
Nginx is a powerful tool, and you've just unlocked its potential. Happy hosting!
Join thousands of satisfied customers who have chosen BuyVPS for their hosting needs.
View Plans & PricingUse promo code 5050 for 50% off your first month!