WordPress için En İyi Nginx Yapılandırması (2025)
WordPress için Nginx yapılandırması: FastCGI önbellek, Gzip sıkıştırma, güvenlik başlıkları ve wp-login.php brute force koruması.
WordPress için Nginx Optimizasyonu Neden Önemli?
WordPress, dünya genelinde web sitelerinin %43'ünü çalıştıran en popüler CMS'dir. Ancak yanlış yapılandırılmış bir web sunucusu, WordPress sitesinin yavaş çalışmasına, güvenlik açıklarına ve gereksiz sunucu yüküne yol açabilir. Doğru Nginx yapılandırması ile sayfa yükleme sürelerini dramatik biçimde kısaltabilir, güvenliği artırabilir ve sunucu maliyetlerini düşürebilirsiniz.
Bu rehberde FastCGI önbellekleme, Gzip sıkıştırma, tarayıcı önbellekleme, güvenlik başlıkları ve WordPress'e özgü Nginx optimizasyonlarını ele alacağız.
Temel WordPress Nginx Yapılandırması
sudo nano /etc/nginx/sites-available/wordpress
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name example.com www.example.com;
root /var/www/wordpress;
index index.php;
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;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
# Güvenlik başlıkları
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
# WordPress permalinks
location / {
try_files $uri $uri/ /index.php?$args;
}
# PHP işleme
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
# Statik dosyalar için tarayıcı önbellekleme
location ~* \.(css|js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 30d;
add_header Cache-Control "public, no-transform";
add_header Vary Accept-Encoding;
access_log off;
}
# Güvenlik - hassas dosyaları gizle
location ~ /\. { deny all; }
location = /wp-config.php { deny all; }
location ~* wp-config.php { deny all; }
# XML-RPC engelle (gerekli değilse)
location = /xmlrpc.php {
deny all;
return 444;
}
# Upload klasöründe PHP çalıştırmayı engelle
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
client_max_body_size 64M;
}
FastCGI Cache ile Dinamik Sayfa Önbellekleme
sudo nano /etc/nginx/nginx.conf
http {
# FastCGI cache tanımı (http bloğunda)
fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=WP_CACHE:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
}
server {
# Cache bypass koşulları
set $skip_cache 0;
if ($request_method = POST) { set $skip_cache 1; }
if ($query_string != "") { set $skip_cache 1; }
if ($request_uri ~* "/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap") { set $skip_cache 1; }
if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") { set $skip_cache 1; }
location ~ \.php$ {
fastcgi_cache WP_CACHE;
fastcgi_cache_valid 200 60m;
fastcgi_cache_use_stale error timeout updating invalid_header;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
add_header X-FastCGI-Cache $upstream_cache_status;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
}
sudo mkdir -p /var/run/nginx-cache
sudo chown www-data:www-data /var/run/nginx-cache
Gzip Sıkıştırma
sudo nano /etc/nginx/conf.d/gzip.conf
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/xml+rss
application/atom+xml
image/svg+xml;
gzip_min_length 1000;
WordPress wp-login.php Brute Force Koruması
limit_req_zone $binary_remote_addr zone=wp_login:10m rate=1r/m;
location = /wp-login.php {
limit_req zone=wp_login burst=3 nodelay;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
PHP-FPM Optimizasyonu
sudo nano /etc/php/8.1/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
Yapılandırmayı Aktifleştirme
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx php8.1-fpm
Cache Kontrolü
# Cache durumunu başlıkta kontrol et
curl -I https://example.com/ | grep X-FastCGI-Cache
# HIT: Önbellekten sunuldu
# MISS: İlk istek, önbellekte değil
# BYPASS: Koşul nedeniyle atlandı
Sonuç
WordPress için Nginx yapılandırmasını FastCGI cache, Gzip sıkıştırma, tarayıcı önbellekleme ve güvenlik önlemleriyle optimize ettiniz. Doğru ayarlanmış bu yapı, yüksek trafikli WordPress sitelerini bile minimum sunucu kaynağıyla hızlı ve güvenli biçimde servis eder.
Yorumlar
Henüz yorum yok. İlk yorumu siz yapın!