一、 概述
提供web服務的中間件;是目前應用比較廣泛的web服務程式;開源軟體,輕量級的。
使用http協定傳輸,預設監聽的端口:http:80;https:443
二、 安裝
rpm包:
rpm -ivh ;yum;源碼
deb包:
dpkg -i ; apt-get ; 源碼
1) 基本環境
IP,firewalld,selinux
2) 配置yum源
echo -e "[local]\nname=local\nbaseurl=file:///mnt\nenbaled=1\ngpgcheck=0" > local.repo
3) yum install httpd
4) 啟動服務
systemctl start httpd
5) 在Linux系統下的通路指令:
curl IP ; elinks IP
三、 配置
配置檔案路徑:/etc/httpd/conf
ServerRoot "/etc/httpd" //軟體安裝根目錄
Listen 80 //監聽配置
User apache //運作使用者
Group apache //運作組
ServerAdmin root@localhost //管理者郵箱
<Directory /> //安裝根目錄通路權限
AllowOverride none
Require all denied
</Directory>
ServerName www.example.com:80 //服務通路域名
DocumentRoot "/var/www/html" //通路頁面根目錄
<Directory "/var/www"> //通路權限
AllowOverride None
Require all granted
<Directory "/var/www/html"> //通路權限
Options Indexes FollowSymLinks
<IfModule dir_module>
DirectoryIndex index.html //預設通路頁面格式
</IfModule>
ErrorLog "logs/error_log" //錯誤日志
LogLevel warn //日志級别
<IfModule log_config_module>
CustomLog "logs/access_log" combined //成功通路日志
AddDefaultCharset UTF-8 //字元集設定
四、 虛拟主機頭配置
配置檔案路徑: /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf
利用不同的IP位址實作
1) 配置子接口IP
ifconfig ens33:0 192.168.1.2/24
2) 建立不同web 的通路目錄
cd /var/www && mkdir web1 web2
3) 修改配置檔案
Listen 192.168.1.1:80
Listen 192.168.1.2:80
<VirtualHost 192.168.1.1:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/web1"
ServerName web1.zhao.com
ServerAlias web01.zhao.com
ErrorLog "/var/log/httpd/web1-error_log"
CustomLog "/var/log/httpd/web1-access_log" common
</VirtualHost>
<VirtualHost 192.168.1.2:80>
DocumentRoot "/var/www/web2"
ServerName web2.zhao.com
ServerAlias web02.zhao.com
ErrorLog "/var/log/httpd/web2-error_log"
CustomLog "/var/log/httpd/web2-access_log" common
-
- 利用不同的端口号實作
- 利用不同的域名實作
通路時需要有DNS解析,若沒有則修改hosts檔案:
Linux:vim /etc/hosts
Windows:C:/windows/system32/drivers/etc/hosts