Hello, I'm Arthur.
Deploying a website on a Linux VPS is a useful skill for developers who want more control over their hosting environment.
You can configure the web server, manage your website files, and connect your domain without depending on a traditional shared hosting control panel.
In this guide, I'll explain how to deploy a simple website using Ubuntu and Nginx.
1. Prepare your VPS
Start with a Linux VPS running Ubuntu. You will also need a domain name if you want visitors to access your website through a custom domain.
Before installing anything, update the server:
sudo apt update
sudo apt upgrade
A VPS provides a virtual server environment where you can install and configure the software your website requires.
When comparing hosting options, consider the available CPU, RAM, storage, and network capacity. For example, Seimaxim VPS hosting is an option to explore for website hosting and development projects.
2. Install Nginx
Nginx is a web server commonly used to serve websites and handle HTTP requests.
Install it with:
sudo apt install nginx
Check whether the service is running:
sudo systemctl status nginx
If it is not running, start it:
sudo systemctl start nginx
You can also enable it to start automatically when the server boots:
sudo systemctl enable nginx
3. Configure the firewall
Your website needs to accept incoming HTTP and HTTPS connections.
If UFW is enabled, allow the Nginx web traffic profile:
sudo ufw allow 'Nginx Full'
Check the firewall rules:
sudo ufw status
The Nginx Full profile allows traffic on ports 80 and 443.
Make sure your SSH connection is also allowed before enabling or changing firewall rules. Otherwise, you could lose access to your server.
4. Upload your website files
Create a directory for your website:
sudo mkdir -p /var/www/example.com/html
Create a simple HTML file:
sudo nano /var/www/example.com/html/index.html
Add the following content:
<!DOCTYPE html>
<html>
<head>
<title>My Website</title>
</head>
<body>
<h1>Welcome to my website</h1>
<p>This website is running on Nginx.</p>
</body>
</html>
Save the file and exit the editor.
Set the directory ownership and permissions appropriately so that Nginx can read the website files.
For a simple static website, the web server only needs read access to the files and execute access to the directories.
5. Create an Nginx server block
A server block allows Nginx to serve a website using its domain name.
Create a configuration file:
sudo nano /etc/nginx/sites-available/example.com
Add this configuration:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/example.com/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Replace example.com with your actual domain.
Enable the configuration:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
Test the configuration before reloading Nginx:
sudo nginx -t
If the test is successful, reload the service:
sudo systemctl reload nginx
6. Point your domain to the server
Your domain's DNS records must point to the VPS.
Usually, you need:
- An A record for the root domain pointing to the server's IPv4 address.
- An A record for
wwwpointing to the same address, or a CNAME pointing to the root domain.
DNS changes can take time to become visible everywhere.
You can check the domain's resolved address with:
dig example.com
If the command is unavailable, install the DNS utilities package for your distribution.
7. Enable HTTPS
Once the domain points to the server and HTTP access works, configure HTTPS.
For a domain using Nginx on Ubuntu, Certbot can help obtain and install a certificate from Let's Encrypt.
Install the appropriate Certbot packages for your operating system, then follow the official Certbot instructions for Nginx.
After installation, test that the website loads over HTTPS and that HTTP requests are redirected correctly if you have configured a redirect.
A valid TLS certificate protects the connection between the visitor and your website.
8. Test the website
Open your domain in a browser and confirm that the page loads correctly.
You can also test the response from the terminal:
curl -I https://example.com
If the website does not work, check the Nginx service status:
sudo systemctl status nginx
Review the error log:
sudo tail -n 50 /var/log/nginx/error.log
Common problems include incorrect DNS records, firewall rules, file permissions, and mistakes in the Nginx configuration.
For websites that receive more traffic or run additional services, review the server's resource usage and hosting requirements as well. Seimaxim dedicated servers are another option to consider when a project needs dedicated physical resources.
Final thoughts
Deploying a website on a Linux VPS becomes much easier when you follow a clear process.
Prepare the server, install Nginx, configure the website directory, connect your domain, and enable HTTPS.
Always test configuration changes before applying them, and keep regular backups of your website files and configuration.
With these basic steps, you can get a simple website running on your own Linux server and build on that setup as your project grows.
Top comments (0)