HxHippy

Installing Nginx

How to install Nginx on various Linux distributions and FreeBSD.

Last updated: 2025-01-15

Installation Methods

Debian/Ubuntu

# Update packages
sudo apt update

# Install nginx
sudo apt install nginx

# Start and enable
sudo systemctl start nginx
sudo systemctl enable nginx

# Verify
nginx -v
sudo systemctl status nginx

RHEL/CentOS/Rocky/Alma

# Install EPEL repository (if needed)
sudo dnf install epel-release

# Install nginx
sudo dnf install nginx

# Start and enable
sudo systemctl start nginx
sudo systemctl enable nginx

# Open firewall
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

FreeBSD

# Install from packages
pkg install nginx

# Enable in rc.conf
sysrc nginx_enable="YES"

# Start nginx
service nginx start

Arch Linux

# Install nginx
sudo pacman -S nginx

# Start and enable
sudo systemctl start nginx
sudo systemctl enable nginx

Docker

# Pull official image
docker pull nginx:alpine

# Run container
docker run -d -p 80:80 -p 443:443 \
  -v /path/to/nginx.conf:/etc/nginx/nginx.conf:ro \
  -v /path/to/html:/usr/share/nginx/html:ro \
  --name nginx nginx:alpine

Verify Installation

# Check version
nginx -v

# Test configuration
nginx -t

# View running processes
ps aux | grep nginx

# Check listening ports
ss -tlnp | grep nginx

Default Locations

Distribution Config Root Logs
Debian/Ubuntu /etc/nginx/ /var/www/html /var/log/nginx/
RHEL/CentOS /etc/nginx/ /usr/share/nginx/html /var/log/nginx/
FreeBSD /usr/local/etc/nginx/ /usr/local/www/nginx /var/log/nginx/
beginner Getting Started Updated 2025-01-15
  • nginx
  • installation
  • linux
  • debian
  • ubuntu
  • centos
  • freebsd