Overview
Nginx is a high-performance web server and reverse proxy, well suited to high-traffic sites and as a front end for PHP-FPM, Node.js or other application servers. This article shows how to install Nginx, serve a static site and configure a PHP-enabled server block on an ALYPOD CPU Pod.
Before you begin
- A CPU Pod with root/sudo access.
- Ports 80 and 443 allowed in the ALYPOD firewall.
- Optional: PHP-FPM for dynamic content.
Steps
Install
```bash
Debian / Ubuntu
sudo apt update && sudo apt install -y nginx
RHEL / AlmaLinux / Rocky
sudo dnf install -y nginx ```
Start and enable
bash
sudo systemctl enable --now nginx
sudo systemctl status nginx
Serve a static site
- Create the web root:
bash
sudo mkdir -p /var/www/example.com/html
echo "<h1>Hello from ALYPOD</h1>" | sudo tee /var/www/example.com/html/index.html
sudo chown -R www-data:www-data /var/www/example.com
- Create
/etc/nginx/conf.d/example.com.conf(orsites-availableon Debian):
```nginx server { listen 80; server_name example.com www.example.com; root /var/www/example.com/html; index index.html index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
} ```
- Test the configuration and reload:
bash
sudo nginx -t
sudo systemctl reload nginx
Reverse proxy example
To front an app listening on 127.0.0.1:3000:
nginx
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
Troubleshooting
- Problem: 502 Bad Gateway. Solution: The upstream (PHP-FPM or app) is down or the
socket path is wrong — check
systemctl status php*-fpm. - Problem: Nginx will not start after an edit. Solution: Run
nginx -tto see the exact syntax error and line number. - Problem: PHP downloads instead of executing. Solution: Ensure the
.phplocation block passes to FPM; thefastcgi_passsocket must exist.
Related articles
- [Installing the Apache web server]
- [Installing PHP and common extensions]
- [Setting up a free Let's Encrypt SSL certificate]
