How do I install Nginx on a Linux server?
Install and start Nginx
Nginx is a common web server and reverse proxy on Linux. On Ubuntu or Debian, refresh the package list first with sudo apt update, then install it with sudo apt install nginx. The package usually starts the service right away, but enabling it makes sure it comes back after a reboot.
Run sudo systemctl status nginx to confirm the service is active. Then visit your server IP address in a browser and look for the default Nginx welcome page. If you do not see it, check the service status and firewall before changing anything else.
- sudo apt update
- sudo apt install nginx
- sudo systemctl enable --now nginx
- sudo systemctl status nginx
Open the firewall and test changes
If you use ufw, allow web traffic with sudo ufw allow 'Nginx Full' to open both HTTP and HTTPS, or sudo ufw allow 80/tcp at minimum. Check the rules with sudo ufw status. Other distributions may use firewalld or iptables, so the commands differ.
Site configuration on Debian and Ubuntu usually lives in /etc/nginx/sites-available. Test any change with sudo nginx -t before reloading with sudo systemctl reload nginx. That test catches typos before they take your site offline.
Keep it running
Watch for port conflicts if another web server, such as Apache, is already using port 80. Stop or move the conflicting service before starting Nginx. Logs for Nginx are available with journalctl -u nginx.
Common mistakes
- Editing the config and reloading without running nginx -t first.
- Forgetting to open port 80 or 443, then assuming Nginx is broken.
- Installing Nginx on a server where another web server already owns port 80.
