tatli_cadi
Yeni Üye
Senaryo
Bir ana domain ve bazı alt‑domain’leri (ör.example.com, blog.example.com, shop.example.com) barındırıyorsunuz. HTTPS’e geçişi zorunlu kılmak istiyor ancak alt‑domain adreslerinin aynı kalmasını istiyorsunuz.Nginx Yapılandırması
- 80 portu için sunucu bloğu
NGINX:server { listen 80; server_name example.com blog.example.com shop.example.com; return 301 https://$host$request_uri; }
return 301301 Kalıcı yönlendirme gönderir.$hostdeğişkeni gelen isteğin başlığındaki host kısmını alır; bu sayedeblog.example.comgibi alt‑domainler korunur.$request_uritam istek yolunu (path + query) içerir.
- 443 portu için SSL bloğu
NGINX:server { listen 443 ssl; server_name example.com blog.example.com shop.example.com; ssl_certificate /etc/ssl/certs/example.crt; ssl_certificate_key /etc/ssl/private/example.key; # Diğer ayarlar... }
Kontrol
curl -I http://blog.example.com/test
Kod:HTTP/1.1 301 Moved Permanently Location: https://blog.example.com/test- Tarayıcıda
http://shop.example.com/page?item=12adresine girdiğinizdehttps://shop.example.com/page?item=12olarak yeniden yönlendirildiği görülür.
Yeniden Yükleme
Yapıyı değiştirdikten sonra
Bash:
sudo nginx -t # Test
sudo systemctl reload nginx
Soru: Alt‑domain desteğini tek
server_name _; ile yapmak mı yoksa her domaini listelerken korumayı tercih etmek mi daha verimli olur?