Nginx vs Apache: Web Server Karşılaştırması ve Konfigürasyonu

z

zafer ak

Yazar

11 November 2025 2 dakika okuma 2 görüntülenme
Nginx vs Apache: Web Server Karşılaştırması ve Konfigürasyonu
Nginx ve Apache web server karşılaştırması. Laravel için optimal konfigürasyon ve performance tuning.

Nginx vs Apache Genel Bakış

Her iki web server da production-ready ve yaygın kullanılır. Farklı mimariler ve güçlü yönleri vardır.

Mimari Farklar

Apache

  • Process/thread-based
  • Her bağlantı için yeni process/thread
  • .htaccess ile directory-level config
  • mod_php ile PHP entegrasyonu

Nginx

  • Event-driven, asynchronous
  • Single-threaded worker processes
  • Merkezi konfigürasyon
  • Reverse proxy olarak PHP-FPM

Performans Karşılaştırması

MetrikApacheNginx
Static contentİyiMükemmel
Concurrent connectionsOrtaMükemmel
Memory usageYüksekDüşük
Dynamic contentMükemmel (mod_php)İyi (PHP-FPM)

Nginx Laravel Konfigürasyonu

server {
    listen 80;
    server_name example.com;
    root /var/www/example/public;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";

    index index.php;
    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}

Apache Laravel Konfigürasyonu

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/example/public

    <Directory /var/www/example/public>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

# .htaccess (public/)
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

SSL/TLS Konfigürasyonu

# Nginx
server {
    listen 443 ssl http2;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;
}

# HTTP to HTTPS redirect
server {
    listen 80;
    return 301 https://$host$request_uri;
}

Gzip Compression

# Nginx
gzip on;
gzip_comp_level 5;
gzip_types text/plain text/css application/json application/javascript text/xml;

# Apache
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/css application/javascript
</IfModule>

Hangisini Seçmeli?

Nginx Tercih Edin

  • Yüksek trafik siteleri
  • Static content ağırlıklı
  • Reverse proxy/load balancer
  • Memory kısıtlı ortamlar

Apache Tercih Edin

  • Shared hosting
  • .htaccess gerekli
  • Mevcut Apache modülleri
  • Legacy uygulamalar

Sonuç

Modern projelerde Nginx genellikle tercih edilir. Ancak Apache'nin .htaccess esnekliği bazı senaryolarda avantajdır.

İlgili Yazılar