How to Set Up an Nginx Web Server on Ubuntu VPS
Prerequisites:
Ubuntu running VPS (18.04 or later).
SSH access to your server.
Step 1: Connect to Your VPS
Open your terminal and connect to your VPS via SSH:
ssh username@your_server_ip
Replace username with your actual username and your_server_ip with the IP address of your server.
Step 2: Update Your Package Index
Before installing any packages, it is advisable to refresh the package index:
sudo apt update
Step 3: Install Nginx
To install Nginx, do:
sudo apt install nginx
Step 4: Start and Enable Nginx
Nginx Webserver
After installation is complete, start the Nginx service and enable it to start automatically on system boot:
sudo systemctl start nginx
sudo systemctl enable nginx
Step 5: Configure Firewall
If the firewall is running, allow HTTP and HTTPS traffic through it:
How to Set Up an Nginx Web Server on Ubuntu VPS
sudo ufw allow ‘Nginx Full’
Step 6: Check Nginx Status
You can check if Nginx is running with:
sudo systemctl status nginx
Step 7: Setup a Simple HTML Page
Create a new HTML file in the default directory of Nginx:
sudo nano /var/www/html/index.html
Add the following content:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to My Nginx Server!</title>
</head>
<body>
<h1>Hello, World!
This is a simple Nginx web server!
</body>
</html>
Save and exit.
Step 8: Test Your Web Server
Open a web browser and go to your server’s IP address, something like http://your_server_ip. You will see your HTML page!
Step 9: (Optional) Setup A Domain Name
If you have a domain name, you can set up Nginx to host your site on your domain. First, open the Nginx configuration file:
sudo nano /etc/nginx/sites-available/default
Change the server_name directive to your domain:
server_name your_domain.com;
Restart Nginx:
sudo systemctl restart nginx
Wrapping Up
Now you are hosting a simple web server with Nginx on your VPS! Later on, you could do whatever you want to cost as easily as adding SSL certificates, setting virtual hosts, or even deploying web applications. Cheers to your brand-new server!
Top comments (0)