Nginx: install and your first site
In this article you'll install Nginx on your mHost VPS, enable it as a systemd service, publish a simple static site behind its own server block (vhost), and open the ports it needs in the firewall.

What you'll need
- An mHost VPS running Ubuntu 22.04/24.04, Debian 11/12, or AlmaLinux/Rocky Linux 8/9.
- SSH access as root or a user with sudo.
- A domain pointed at the server's IP address. For testing, the bare IP works too — you can set
server_namelater.
Step 1. Install Nginx
Ubuntu / Debian
apt update
apt install nginxAlmaLinux / Rocky Linux
dnf install nginxThe nginx package is already in the standard repository (AppStream) — no third-party repo needed.
Check that it installed:
nginx -vStep 2. Enable and start Nginx via systemd
systemctl enable --now nginx
systemctl status nginxenable --now both adds Nginx to startup and starts it immediately. The status should show active (running).
Check that the server responds — right on the VPS, before you've opened anything in the firewall:
curl -I http://127.0.0.1/An HTTP/1.1 200 OK response with a Server: nginx header means Nginx is running and serving its default page.
Step 3. Publish a static site
Create a dedicated folder for the site and drop an index.html into it:
mkdir -p /var/www/example.com/htmlcat > /var/www/example.com/html/index.html <<'EOF'
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<title>example.com</title>
</head>
<body>
<h1>Nginx работает!</h1>
<p>Это статический сайт, размещённый на VPS mHost.</p>
</body>
</html>
EOFStep 4. Configure a server block (vhost)
The configuration is identical for both distro families — only the file path differs.
Ubuntu / Debian: sites-available and sites-enabled
cat > /etc/nginx/sites-available/example.com <<'EOF'
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;
}
}
EOFEnable the site with a symlink into sites-enabled:
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/AlmaLinux / Rocky: conf.d
cat > /etc/nginx/conf.d/example.com.conf <<'EOF'
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;
}
}
EOFThe .conf extension is required — only files with it get picked up by the include /etc/nginx/conf.d/*.conf; directive in /etc/nginx/nginx.conf. There's no separate enable step: anything in conf.d is already active.
dnf install policycoreutils-python-utils
semanage fcontext -a -t httpd_sys_content_t "/srv/example.com(/.*)?"
restorecon -Rv /srv/example.comStep 5. Test the configuration and reload Nginx
nginx -tYou should see syntax is ok and test is successful. Only then reload the configuration:
systemctl reload nginxreload picks up the changes without dropping existing connections — unlike restart, which restarts Nginx entirely.
Check that your site is now the one answering by name:
curl -I -H "Host: example.com" http://127.0.0.1/Step 6. Open ports 80 and 443 in the firewall
Ubuntu / Debian (ufw)
apt install ufw
ufw allow 80/tcp
ufw allow 443/tcpAlmaLinux / Rocky (firewalld)
These distros use firewalld by default, not ufw — it's normally already installed and running (check with systemctl status firewalld):
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reloadWhat's next
Right now the site is only reachable over HTTP. To enable HTTPS, set up a Let's Encrypt certificate via Certbot — that's a separate topic. If you need a PHP backend with a database instead of a static site, check out the LEMP recipe in the "Ready-made VMmanager 6 recipes" article — it brings up Nginx, MySQL, and PHP in a single run.