Published: 30.09.2026
Nginx is a widely used web server that can serve static websites and forward requests to applications. On a VPS with root access you can install it, write a server block for your domain, test the configuration and reload the service without dropping visitors. This article walks through the process for Debian and Ubuntu and ends with the step that comes next: HTTPS.

Install and check the service
Refresh the package list and install Nginx with the package manager. On Debian and Ubuntu the commands are apt update and then apt install nginx, with sudo in front if you are not logged in as root. Check that the service is running with systemctl status nginx. When it runs, open the server's IP address in a browser, and you should see the default welcome page.
Create a folder for the site
Keep each site in its own folder, outside the system folders. A common pattern is a folder under /var/www named after the domain, with a public subfolder for the files. Place a simple index.html file inside it, so you can test the setup before you upload the real website. Give the folder to the user who uploads the files, and avoid making it writable by everyone.
Write the server block
Nginx reads site definitions from its configuration folders. On Debian and Ubuntu, create a file named after your domain in /etc/nginx/sites-available. In that file, write a server block with three important settings: the server name set to your domain, the root path set to your public folder, and the index file set to index.html. Then create a link to the file in /etc/nginx/sites-enabled with the ln command and the symbolic option, which switches the site on. If the default site is still enabled, remove its link. Deleting a link does not delete the file it points to.
Test before you reload
Never reload Nginx without testing the configuration first. Run nginx with the test option, which checks the syntax of every file and reports errors with the file name and line number. When the test reports success, reload the service with systemctl reload nginx. A reload applies the new settings gracefully, while a restart drops active connections.
Point the domain and check the result
To reach the site by name, create an A record for the domain that points to the server's IPv4 address, and an AAAA record for the IPv6 address if you use it. Premium DNS works with any registrar, so the records can live there if you use it. After the DNS change has spread, open the domain in a browser. If the page does not appear, read the error log in /var/log/nginx with the tail command. It records what went wrong and usually names the file responsible.
Firewall rules for web traffic
Allow the Nginx profile in the firewall. The command ufw app list shows the profile names. Keep SSH allowed as well, and check the status after each change. The free firewall in the client area can be used together with the server firewall. Open only the web traffic you need, and restrict SSH to known addresses where practical.
Next step: HTTPS
Once the plain site works, add HTTPS. A free certificate from a certificate authority such as Let's Encrypt, usually installed with a helper tool, encrypts traffic and gives visitors the padlock in their browser. Then redirect HTTP to HTTPS, make sure renewal runs automatically and test the renewal with the tool's dry-run option. On a VPS you set up and renew the certificate yourself.
Frequently asked questions
Why do I see the default page instead of my site? The default site may still be enabled, or the root path points to the wrong folder. Check the links in sites-enabled and the root line, then run the test and reload.
Do I need to restart after every change? Usually a reload is enough. Always run the configuration test first, so that a small typo does not stop the service.
Is Nginx better than Apache? Neither is better in every case. Nginx is often used for static files and as a front end for applications, and Apache is also common. Choose the one your application supports and that you can maintain.