Veb server: httpd, virtual host, SELinux və firewalld ilə
Bu dərs hamı üçün açıqdır. Qalan dərslər paketlə açılır: daxil ol və ya qeydiyyatdan keç, sonra paket seç.
Əsas fikirlər
- httpd ayarı: əsas
/etc/httpd/conf/httpd.conf, öz fayllarımız/etc/httpd/conf.d/*.conf; yoxlamahttpd -t(apachectl configtest). - Virtual host: bir IP-də bir neçə sayt,
ServerName-ə görə ayrılır:<VirtualHost *:80> ServerName shop.itnuvo.local DocumentRoot /srv/shop </VirtualHost>. - Yeni DocumentRoot üçün: qovluq icazəsi +
<Directory>bloku + SELinux konteksti (semanage fcontext+restorecon). - Ardıcıllıq:
dnf install→ ayar →httpd -t→enable --now→firewall-cmd→ SELinux →curl. - Loglar:
/var/log/httpd/error_log,access_log; hər vhost üçün ayrıca log yaz.
Hədəf arxitektura
Simulyatorun lab dünyasında srv-web01 veb server, srv-db01 verilənlər bazası, client01 istifadəçidir. Bu bölmədə onu real xidmətlərlə doldururuq:
client01 (10.20.0.50) │ http://www.itnuvo.local, http://shop.itnuvo.local ▼ srv-web01 (10.20.0.15) — httpd: iki virtual host │ 3306/tcp (8.2), NFS (8.3) ▼ srv-db01 (10.20.0.20) — MariaDB, NFS
Addım 1–3: quraşdır, işə sal, aç
Əvvəlki bölmələrdən tanış:
[ali@srv-web01 ~]$ sudo dnf install -y httpd [ali@srv-web01 ~]$ sudo systemctl enable --now httpd [ali@srv-web01 ~]$ sudo firewall-cmd --permanent --add-service=http && sudo firewall-cmd --reload [ali@srv-web01 ~]$ curl -s -o /dev/null -w "%{http_code}\n" http://localhost 403
403 təəccüblü deyil: /var/www/html boşdur və RHEL-in "welcome" səhifəsi 403 kodu ilə qaytarılır. Brauzerdə "Test Page" görünür.
Ayar faylları
| Fayl / qovluq | Nədir |
|---|---|
/etc/httpd/conf/httpd.conf | Əsas ayar — Listen 80, DocumentRoot "/var/www/html", User apache |
/etc/httpd/conf.d/*.conf | Əlavə ayarlar — öz saytlarını bura yaz |
/etc/httpd/conf.modules.d/ | Modulların yüklənməsi |
/var/www/html | Standart məzmun |
/var/log/httpd/ | access_log, error_log |
RHEL-də httpd prosesləri apache istifadəçisi adından işləyir (Ubuntu-da www-data).
Birinci sayt: standart qovluqda
[ali@srv-web01 ~]$ sudo mkdir -p /var/www/www.itnuvo.local [ali@srv-web01 ~]$ echo "<h1>ITNuvo - ana sayt</h1>" | sudo tee /var/www/www.itnuvo.local/index.html [ali@srv-web01 ~]$ sudo tee /etc/httpd/conf.d/www.conf > /dev/null <<'EOF' <VirtualHost *:80> ServerName www.itnuvo.local DocumentRoot /var/www/www.itnuvo.local ErrorLog /var/log/httpd/www-error.log CustomLog /var/log/httpd/www-access.log combined </VirtualHost> EOF [ali@srv-web01 ~]$ sudo httpd -t Syntax OK [ali@srv-web01 ~]$ sudo systemctl reload httpd
/var/www altında yaradılan qovluq SELinux kontekstini (httpd_sys_content_t) avtomatik alır — əlavə iş lazım deyil.
İkinci sayt: /srv/shop — dörd qat
[ali@srv-web01 ~]$ sudo mkdir -p /srv/shop [ali@srv-web01 ~]$ echo "<h1>ITNuvo Shop</h1>" | sudo tee /srv/shop/index.html [ali@srv-web01 ~]$ sudo tee /etc/httpd/conf.d/shop.conf > /dev/null <<'EOF' <VirtualHost *:80> ServerName shop.itnuvo.local DocumentRoot /srv/shop <Directory /srv/shop> Require all granted </Directory> ErrorLog /var/log/httpd/shop-error.log CustomLog /var/log/httpd/shop-access.log combined </VirtualHost> EOF [ali@srv-web01 ~]$ sudo httpd -t && sudo systemctl reload httpd [ali@srv-web01 ~]$ curl -s -o /dev/null -w "%{http_code}\n" -H "Host: shop.itnuvo.local" http://localhost 403
Ayar düzdür, amma 403. Dörd qatı yoxlayaq:
| Qat | Yoxla | Nəticə |
|---|---|---|
| 1. httpd ayarı | <Directory> bloku, Require all granted | ✓ (httpd / üçün standart olaraq Require all denied qoyur — blok olmasa 403) |
| 2. Fayl icazəsi | ls -ld /srv/shop, ls -l /srv/shop | ✓ 755 / 644 — apache oxuya bilir |
| 3. SELinux | ls -Zd /srv/shop | ✗ var_t |
| 4. Firewall | Lokal sorğudur, təsiri yoxdur | — |
[ali@srv-web01 ~]$ ls -Zd /srv/shop unconfined_u:object_r:var_t:s0 /srv/shop [ali@srv-web01 ~]$ sudo semanage fcontext -a -t httpd_sys_content_t "/srv/shop(/.*)?" [ali@srv-web01 ~]$ sudo restorecon -Rv /srv/shop Relabeled /srv/shop from unconfined_u:object_r:var_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 Relabeled /srv/shop/index.html from unconfined_u:object_r:var_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0 [ali@srv-web01 ~]$ curl -s -H "Host: shop.itnuvo.local" http://localhost <h1>ITNuvo Shop</h1>
Bu, RHCSA-nın ən klassik tapşırığıdır — və SELinux-u söndürmədən həll olunur.
Klientdən yoxlama
client01-də adları /etc/hosts-a yazırıq (real şəbəkədə DNS-də olardı):
ali@client01:~$ echo "10.20.0.15 www.itnuvo.local shop.itnuvo.local" | sudo tee -a /etc/hosts ali@client01:~$ curl -s http://www.itnuvo.local <h1>ITNuvo - ana sayt</h1> ali@client01:~$ curl -s http://shop.itnuvo.local <h1>ITNuvo Shop</h1>
Eyni IP, iki fərqli sayt — httpd sorğudakı Host başlığına baxıb düzgün VirtualHost-u seçir.
HTTPS (qısa)
[ali@srv-web01 ~]$ sudo dnf install -y mod_ssl [ali@srv-web01 ~]$ sudo firewall-cmd --permanent --add-service=https && sudo firewall-cmd --reload [ali@srv-web01 ~]$ sudo systemctl restart httpd [ali@srv-web01 ~]$ curl -sk -o /dev/null -w "%{http_code}\n" https://localhost 403
mod_ssl öz-özünə imzalanmış sertifikatla 443-ü açır. İstehsalda real sertifikat (SSLCertificateFile, SSLCertificateKeyFile) yazılır; açar faylının icazəsi 600, konteksti cert_t olmalıdır.
Problem olanda
[ali@srv-web01 ~]$ sudo tail -n 3 /var/log/httpd/shop-error.log [ali@srv-web01 ~]$ sudo ausearch -m AVC -ts recent -c httpd [ali@srv-web01 ~]$ sudo httpd -S VirtualHost configuration: *:80 is a NameVirtualHost default server shop.itnuvo.local (/etc/httpd/conf.d/shop.conf:1) port 80 namevhost shop.itnuvo.local (/etc/httpd/conf.d/shop.conf:1) port 80 namevhost www.itnuvo.local (/etc/httpd/conf.d/www.conf:1)
httpd -S bütün virtual host-ları və hansının standart olduğunu göstərir — Host başlığı heç birinə uyğun gəlməyəndə əlifba sırası ilə birinci fayl (burada shop.conf) cavab verir.
Lab: iki sayt
Red Hat simulyatorunda "httpd-ni işə sal", "firewalld: saytı şəbəkəyə aç" və "SELinux: 403 Forbidden" tapşırıqları bu dərsin əsas addımlarıdır — üçünü ardıcıl et. Sonra öz VM-ində:
www.itnuvo.localsaytını/var/www/www.itnuvo.local-da qur.shop.itnuvo.localsaytını/srv/shop-da qur:<Directory>, icazələr,semanage fcontext.httpd -t,reload,httpd -S.client01-dən hər iki saytı adla aç.
Yoxlama: iki curl iki fərqli səhifə qaytarır; getenforce → Enforcing.
Özünü yoxla
5 sual · cavab dərhal göstərilir · 3 düzgün cavab dərsi tamamlayır
1Öz virtual host faylını RHEL-də harada yaratmaq lazımdır?
2httpd ayarının sintaksisini hansı əmr yoxlayır?
3Sayt /srv/shop-dadır, icazələr 755/644, Directory bloku var, amma 403 qaytarır. Növbəti addım nədir?
4Bir IP-də bir neçə saytı httpd nəyə görə ayırır?
5RHEL-də httpd prosesləri hansı istifadəçi adından işləyir?
Şərhlər
Şərh yazmaq üçün daxil ol.