apache

安裝httpd

上傳安裝包
yum -y install make gcc gcc-c++ openssl openssl-devel expat-devel ##安裝編譯工具和開發包

unzip lamp.zip ##解壓
Cd lamp/

在這裏插入圖片描述
tar zxvf apr-1.5.2.tar.gz ##解壓apr
cd apr-1.5.2
./configure --prefix=/usr/local/apr

在這裏插入圖片描述

預編譯的時候會報錯
我們把他的文件改一下
vim configure
修改
29605 RM='RM29605RM=RM' 爲: 29605 RM='RM -f’

echo $? ##看一下上條命令執行成功沒

make -j 4 && make install ##編譯安裝

編譯安裝apr-util依賴包
tar -zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4
./configure --prefix=/usr/local/apr-util/
–with-apr=/usr/local/apr/bin/apr-1-config ##預編譯
Make && make install ##編譯安裝

編譯安裝pcre依賴包
tar -zxvf pcre-8.41.tar.gz
cd pcre-8.41
./configure --prefix=/usr/local/pcre
Make && make install

編譯安裝apache
tar -zxcf httpd-2.4.28.tar.gz
cd httpd-2.4.28

./configure --prefix=/usr/local/apache
–enable-so
–enable-rewrite
–enable-ssl
–with-apr=/usr/local/apr
–with-apr-util=/usr/local/apr-util/
–with-pcre=/usr/local/pcre/
–libdir=/usr/lib64 ##預編譯

Make && make install ##編譯安裝

修改配置文件
vim /usr/local/apache/conf/httpd.conf
Listen 80 #監聽端口
ServerRoot “/usr/local/apache” #配置文件根目錄
ServerAdmin [email protected] #管理員郵箱
ServerName localhost:80 #服務器主機名
DocumentRoot “/usr/local/apache/htdocs” #網站根補錄
DirectoryIndex index.html #默認首頁打開html文件

主機名修改爲localhost就可以
在這裏插入圖片描述
##如果自己的網頁路徑不一樣就修改 DocumentRoot

查看網站根目錄
ls /usr/local/apache/htdocs/
cat /usr/local/apache/htdocs/index.html

生成啓動腳本
cp /usr/local/apache/bin/apachectl /etc/init.d/
chmod +x /etc/init.d/apachectl
ll /etc/init.d/apachectl

在這裏插入圖片描述
寫個apache系統服務腳本,以754的權限保存此文件

vim /usr/lib/systemd/system/apache.service

[Unit]
Description=apache
After=network.target
[Service]
Type=forking
ExecStart=/etc/init.d/apachectl start
ExecReload=/etc/init.d/apachectl restart
ExecStop=/etc/init.d/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

chmod 754 /usr/lib/systemd/system/apache.service ##添加權限

添加開機自啓
systemctl enable apache

啓動服務
/etc/init.d/apachectl restart

查看端口
netstat -antup | grep 80
在這裏插入圖片描述
測試訪問192.168.100.10

在這裏插入圖片描述

配置Apache虛擬主機

開啓虛擬主機功能
vim /usr/local/apache/conf/httpd.conf

#配置文件最下面 啓用這一行
475 #Include conf/extra/httpd-vhosts.conf
去掉#號
475 Include conf/extra/httpd-vhosts.conf

在這裏插入圖片描述

systemctl restart apache ##重啓服務

通過不同ip地址,解析不同域名

給服務器添加ip(另一個域名解析)
Ifconfig ens33:1 192.168.100.20
Ifconfig

在這裏插入圖片描述
創建站點網頁和目錄
mkdir /usr/local/apache/htdocs/bbs
echo “bbs.mingliang.com” > /usr/local/apache/htdocs/bbs/index.html
echo “www.mingliang.com” > /usr/local/apache/htdocs/index.html

定義虛擬主機文件

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

<VirtualHost 192.168.100.10:80>
ServerAdmin [email protected]
DocumentRoot “/usr/local/apache/htdocs/”
ServerName www.bdqn.com
ErrorLog “logs/www.bdqn.com-error_log”
CustomLog “logs/www.bdqn.com-access_log” common

<VirtualHost 192.168.100.20:80>
ServerAdmin [email protected]
DocumentRoot “/usr/local/apache/htdocs/bbs”
ServerName bbs.baqn.com
ErrorLog “logs/bbs.baqn.com-error_log”
CustomLog “logs/bbs.baqn.com-access_log” common

~

在這裏插入圖片描述

systemctl restart apache ##重啓服務

測試
訪問192.168.100.10和20

在這裏插入圖片描述
在這裏插入圖片描述

通過不同的域名配置虛擬主機

定義虛擬主機文件

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

##如果網頁路徑不一樣,上面的權限添加好,路徑改爲自己的
在這裏插入圖片描述
配置hosts映射
vim /etc/hosts
在這裏插入圖片描述
修改客戶端hosts文件
如果在C:\Windows\System32\drivers\etc\目錄下無法修改hosts,可以把hosts拉到桌面, 用記事本打開,修改完,放回去,不要另存爲

在這裏插入圖片描述
systemctl restart apache ##重啓

測試
訪問www.mingliang.com和bbs.mingliang.com

在這裏插入圖片描述

在這裏插入圖片描述

通過不同端口配置虛擬機

添加監聽端口
vim /usr/local/apache/conf/httpd.conf
52行添加

在這裏插入圖片描述
定義虛擬文件

vim /usr/local/apache/conf/extra/httpd-vhosts.conf

在這裏插入圖片描述

systemctl restart apache ##重啓服務

測試
訪問2233和5200端口

在這裏插入圖片描述

在這裏插入圖片描述

到這裏實驗就結束了,做的不好請諒解,如果有什麼問題請小夥伴們留言

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章