RH358學習筆記--8(配置Web伺服器學習)
配置Web伺服器
一、使用Apache HTTPD配置基本Web伺服器
(1)安裝Apache HTTP伺服器
[root@servera ~]# yum -y install httpd
httpd模組支援三個配置檔案:
common:提供生產就緒部署(預設)
minimal:提供可以執行Apache web伺服器的最小軟體包集
devel:提供修改HTTPD所需的包
[root@servera ~]# yum module install httpd:2.4/common
(2)配置Apache HTTP伺服器
Apache HTTP Server讀取它的配置如下:
/etc/httpd/conf/httpd.conf 主配置檔案。
/etc/httpd/conf.d/ 它提供了補充配置檔案,包括在httpd.conf,且檔名以.conf 結尾。
/etc/httpd/conf.modules.d/ 提供了用於動態載入Apache模組的補充配置檔案,且檔名以.conf結尾。
檔案的下一部分將設定應用到伺服器的各個部分,影響從特定位置提供內容的方式,等等。
<Directory />
AllowOverride none
Require all denied
</Directory>
# <Directory>塊設定了應用於指定目錄及其子目錄的配置指令。
<Directory "/var/www">
AllowOverride None
Require all granted
</Directory>
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
# 如果Apache dir_module模組被載入(預設),那麼應用這些指令。DirectoryIndex指令指定如果一個URL被請求指向一個目錄和一個index.html檔案存在於該目錄中,將該檔案提供給客戶端。
<Files ".ht*">
Require all denied
</Files>
# <Files>的工作方式類似於<Directory>塊,但是應用於單個檔案。在這種情況下,它阻止httpd提供敏感檔案,如.htaccess和.htpasswd
(3)啟動Apache HTTP伺服器
[root@servera ~]# systemctl enable --now httpd
安裝httpd包和httpd-manual包。
[root@servera ~]# yum -y install httpd httpd-manual
按要求修改各種
(4)配置Apache HTTPD虛擬主機
使用<virtua lHost>塊指令覆蓋虛擬主機主配置檔案中的設定。每個虛擬主機都有自己的塊。
在/etc/httpd/ conf.d/中單獨的以.conf結尾的配置檔案中配置虛擬主機是一種很好的做法。