Nginx on a VPS: A Beginner’s Installation Guide

Nginx on a VPS: A Beginner’s Installation Guide
If you’re looking to host your website or application with speed and efficiency, Nginx is one of the best web servers to consider. This guide will walk you through the process of installing Nginx on a Virtual Private Server (VPS), making it easy even for beginners. Let’s get started!
Prerequisites
Before you begin, make sure you have the following:
- VPS Access: You need a VPS with SSH access. Providers like Squarebrothers, Linode, or AWS are popular choices.
- Basic Knowledge of Command Line: Familiarity with terminal commands will be helpful.
- Operating System: This guide assumes you are using a Linux distribution, such as Ubuntu.
Step 1: Connect to Your VPS
First, you’ll need to connect to your VPS via SSH. Open your terminal and run:
Replace username
with your actual username and your_vps_ip
with the IP address of your VPS.
Step 2: Update Your System
Before installing Nginx, it’s good practice to update your system packages. Run the following commands:
Step 3: Install Nginx
Now, it’s time to install Nginx. You can do this with a simple command:
This command will download and install Nginx and its dependencies.
Step 4: Start and Enable Nginx
After installation, you’ll want to start the Nginx service and ensure it runs on boot:
Step 5: Check Nginx Status
To verify that Nginx is running, check its status with:
You should see a message indicating that Nginx is active (running).
Step 6: Configure Firewall
If you have a firewall running (like UFW), you’ll need to allow Nginx traffic. You can do this with:
This command opens the necessary ports for HTTP and HTTPS traffic.
Step 7: Access Nginx in Your Browser
Now that Nginx is installed and running, you can check it from your web browser. Simply enter your VPS’s IP address in the address bar:
If everything is set up correctly, you should see the Nginx welcome page.
Step 8: Basic Configuration (Optional)
To configure Nginx for your specific site, you’ll need to edit the default configuration file. Use your preferred text editor (like nano
or vim
):
In this file, you can change the server block settings to point to your website files. After making changes, save the file and exit.
Step 9: Test Configuration and Restart Nginx
Before applying the changes, test the configuration for any syntax errors:
If there are no errors, restart Nginx to apply the changes:
Conclusion

Here are some additional tips for installing Nginx:
- You can install Nginx Open Source directly from nginx.org.
- To configure Nginx to serve files from different directories, you can create a server block inside the http block with two location blocks.
- To set up a virtual host, you can create a file in the /etc/nginx/sites-enabled/ directory.
Nginx is an open-source web server that’s good for load balancing, caching, and acting as a reverse proxy.
Congratulations! You’ve successfully installed Nginx on your VPS. You can now host websites, manage traffic, and explore the many features Nginx has to offer. As you grow more comfortable, consider diving deeper into configuration and optimization to make the most out of your server.