ITNuvoAkademiya
Akademiya ana səhifəPaketlərSiyahılarAlətlərSubnet kalkulyatoruAxtarLüğət
CiscoCCNA · CCNA: network əsasları1. Giriş2. Network Fundamentals3. Network Access4. IP Connectivity5. IP Services6. IPv67. Security Fundamentals8. AutomationCCNP: Enterprise şəbəkələr · tezliklə
LinuxLinux: system administrator üçün · Linux: sistem administratoru (Ubuntu Server)1. Linux ilə tanışlıq2. Mətnlə iş3. İstifadəçilər və icazələr4. Proseslər və paketlər5. Sistemin içi6. Monitorinq və loglar7. ŞəbəkəRed Hat Enterprise Linux · Red Hat Enterprise Linux: başlanğıcdan sona1. Tanışlıq2. Paketlər3. İstifadəçilər və icazələr4. SELinux5. Servislər6. Saxlama7. Şəbəkə8. Servislər qurmaq9. Açılış və bərpa10. DevOps11. Təhlükəsizlik və monitorinq
FortinetFortiGate Administrator · FortiGate Administrator: ilk girişdən ZTNA-ya1. FortiGate ilə tanışlıq2. Routing, policy və NAT3. Təhlükəsizlik profilləri4. İstifadəçilər və loglar5. Dayanıqlıq, SD-WAN və avtomatlaşdırma6. VDOM7. VPN və ZTNA8. Proxy9. DMZ
MonitoringZabbix · Zabbix: qurulmadan bildirişlərə qədər1. Giriş2. Qurulma və verilənlər bazası3. Əsaslar: qruplar, template-lər, istifadəçilər4. Avadanlıqların qoşulması5. Bildirişlər, Grafana və API
VirtualizationProxmox VE · tezlikləVMware ESXi · tezliklə
Hesabım / Daxil ol
AZENRU
← itnuvo.com

Veb server: httpd, virtual host, SELinux və firewalld ilə

Dərs 8.110 dəqİrəli1 dekabr 2026
Açıq

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; yoxlama httpd -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:

text
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ış:

srv-web01
[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 / qovluqNə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/htmlStandart 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

srv-web01
[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

srv-web01
[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:

QatYoxlaNəticə
1. httpd ayarı<Directory> bloku, Require all granted✓ (httpd / üçün standart olaraq Require all denied qoyur — blok olmasa 403)
2. Fayl icazəsils -ld /srv/shop, ls -l /srv/shop✓ 755 / 644 — apache oxuya bilir
3. SELinuxls -Zd /srv/shop✗ var_t
4. FirewallLokal sorğudur, təsiri yoxdur—
srv-web01
[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ı):

client01
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)

srv-web01
[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

srv-web01
[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ə:

  1. www.itnuvo.local saytını /var/www/www.itnuvo.local-da qur.
  2. shop.itnuvo.local saytını /srv/shop-da qur: <Directory>, icazələr, semanage fcontext.
  3. httpd -t, reload, httpd -S.
  4. 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?

conf.d-dəki fayllar avtomatik yüklənir.

2httpd ayarının sintaksisini hansı əmr yoxlayır?

apachectl configtest də eyni işi görü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?

/srv standart olaraq var_t-dir.

4Bir IP-də bir neçə saytı httpd nəyə görə ayırır?

Buna name-based virtual hosting deyilir.

5RHEL-də httpd prosesləri hansı istifadəçi adından işləyir?

Ubuntu-da www-data.
Dərs faydalı oldu?

Şərhlər

Şərh yazmaq üçün daxil ol.