Skip to main content
Nginx serves a site from your server: static files, and PHP too through PHP-FPM. Don’t want to configure it by hand – install Coolify, it sets up the reverse proxy and SSL for you.

Installation

Connect over SSH as root: Connection. The commands are for Ubuntu/Debian, as a regular user add sudo.
  1. Package – the service starts by itself:
  2. Check – open http://your-server-IP in a browser, the “Welcome to nginx!” page should appear. It doesn’t open – port 80 is most likely closed: Firewall.
Apache works instead of Nginx too: apt install apache2. Same principle, different configs and syntax.

Static site

  • /etc/nginx/sites-available/ – configs of all sites.
  • /etc/nginx/sites-enabled/ – symlinks to the enabled sites.
  1. Site files:
  2. Config – create the file /etc/nginx/sites-available/site:
    /etc/nginx/sites-available/site
  3. Enable – symlink, syntax check, and apply without dropping connections:
    Always run nginx -t before reload. If the config has an error, reload won’t apply it and the site keeps running on the old configuration.
The Nginx start page opens instead of your site – the default config intercepts requests. Remove its symlink and reload again: rm /etc/nginx/sites-enabled/default.

PHP

PHP-FPM lets Nginx handle .php: WordPress, scripts.
  1. PHP-FPM:
  2. Socket – its name depends on the PHP version, for example php8.3-fpm.sock:
  3. Handler – add the block inside server { ... } and put in your socket name. With a wrong name Nginx returns a 502 error:
  4. Apply:
  5. Check – create /var/www/site/info.php with the contents <?php phpinfo(); and open http://example.com/info.php: a table of PHP information appears. Then delete the file, it exposes the server configuration.

HTTPS

A free Let’s Encrypt certificate is issued by the certbot tool: SSL and Let’s Encrypt. For the site to be reachable from outside, open ports 80 (HTTP) and 443 (HTTPS) in the firewall: Firewall. Next: SSL and Let’s Encrypt, Server hardening.