Nginx Installatiegids
Omgevingsvereisten
Nginx ondersteunt meerdere besturingssystemen, waaronder:
- Linux (Debian, Ubuntu, CentOS, RHEL, Alpine, enzovoort)
- FreeBSD
- Solaris
- AIX
- HP-UX
- macOS
- Windows
Installatiemethoden
Methode 1: Met de pakketbeheerder (aanbevolen)
Ubuntu/Debian
# Update package index
sudo apt update
# Install Nginx
sudo apt install nginx
# Start Nginx
sudo systemctl start nginx
# Enable on boot
sudo systemctl enable nginx
CentOS/RHEL
# Install EPEL repository
sudo yum install epel-release
# Install Nginx
sudo yum install nginx
# Start Nginx
sudo systemctl start nginx
# Enable on boot
sudo systemctl enable nginx
Alpine
apk add nginx
macOS
# Install using Homebrew
brew install nginx
# Start Nginx
brew services start nginx
Methode 2: Installeren vanuit broncode
Bouwafhankelijkheden installeren
Debian/Ubuntu:
sudo apt install build-essential libpcre3 libpcre3-dev zlib1g-dev libssl-dev
CentOS/RHEL:
sudo yum install gcc pcre-devel zlib-devel openssl-devel
Broncode downloaden
# Download latest stable version
wget https://nginx.org/download/nginx-1.26.0.tar.gz
# Extract
tar -zxf nginx-1.26.0.tar.gz
# Enter directory
cd nginx-1.26.0
Bouw configureren
./configure \
--prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_v3_module \
--with-http_stub_status_module \
--with-pcre
Bouwen en installeren
# Compile
make
# Install
sudo make install
Methode 3: Met Docker
# Pull official image
docker pull nginx
# Run Nginx container
docker run -d -p 80:80 --name mynginx nginx
# Mount configuration and logs
docker run -d -p 80:80 \
-v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro \
-v /host/logs:/var/log/nginx \
--name mynginx nginx
Methode 4: Installatie op Windows
- Download de Windows-versie vanaf https://nginx.org/en/download.html
- Pak uit naar de gewenste map
- Dubbelklik op nginx.exe om te starten
- Of start vanaf de opdrachtregel:
cd C:\nginx
start nginx
Verificatie na de installatie
Installatie controleren
# Check Nginx version
nginx -v
# View detailed version information
nginx -V
Draaistatus controleren
# Check if process is running
ps aux | grep nginx
# Check status using systemctl
systemctl status nginx
Toegang testen
# Use curl to test
curl http://localhost
# Or open browser to access
http://localhost
Mapstructuur
Standaardmappen op Linux
| Pad | Beschrijving |
|---|---|
| /etc/nginx/ | Configuratiemap |
| /etc/nginx/nginx.conf | Hoofdconfiguratiebestand |
| /etc/nginx/conf.d/ | Subconfiguratiemap |
| /var/log/nginx/ | Logboekmap |
| /var/www/html/ | Standaard documentroot |
| /usr/sbin/nginx | Uitvoerbaar bestand |
| /usr/share/nginx/html/ | Standaardmap voor statische bestanden |
Mappen bij installatie vanuit broncode
| Pad | Beschrijving |
|---|---|
| /usr/local/nginx/ | Installatiemap |
| /usr/local/nginx/conf/ | Configuratiemap |
| /usr/local/nginx/html/ | Standaard documentroot |
| /usr/local/nginx/logs/ | Logboekmap |
| /usr/local/nginx/sbin/ | Map met uitvoerbare bestanden |
Nginx verwijderen
Debian/Ubuntu
sudo apt remove nginx nginx-common nginx-full
CentOS/RHEL
sudo yum remove nginx
Installatie vanuit broncode
# Stop Nginx
sudo nginx -s stop
# Remove installation directory
sudo rm -rf /usr/local/nginx
Veelvoorkomende problemen
Poortconflict
Als het starten mislukt door een poortconflict:
# Check port usage
netstat -tulpn | grep :80
# Modify Nginx listening port
# Edit /etc/nginx/nginx.conf
# Change listen 80; to listen 8080;
Rechtenproblemen
Als u fouten met rechten tegenkomt:
# Check Nginx user
ps aux | grep nginx
# Fix file permissions
sudo chown -R www-data:www-data /var/www/html/
Syntaxis van de configuratie controleren
# Test configuration syntax
nginx -t
# Test with specific configuration file
nginx -t -c /path/to/nginx.conf
