Apache2 web服務(wù)器的安裝:
- 第一部選安裝apache2
apt install apache2 -y
- 安裝完畢后扫尖,我們檢查是否啟動(dòng)了Apache服務(wù)
systemctl status apache2
- 我們再來看看一些操作Apache的常用命令
/etc/init.d/apache2 start //啟動(dòng)Apache服務(wù)
/etc/init.d/apache2 stop //停止Apache服務(wù)
/etc/init.d/apache2 restart //重啟Apache服務(wù)
-
下面我們就可以開始訪問我們剛剛配置的Apache服務(wù)器了故慈。打開瀏覽器,輸入http://127.0.0.1/ (這是主機(jī)默認(rèn)的IP地址)或者如果是云主機(jī)就輸入云主機(jī)的IP地址鹦肿。當(dāng)我們看到下面的頁面時(shí)變說明Apache2 服務(wù)已經(jīng)成功在我們的服務(wù)器上工作了。 在這里插入圖片描述
Apache修改網(wǎng)站根目錄及默認(rèn)參數(shù)
我們來試著修改web服務(wù)器的配置,讓我們可以在自己搭建的web服務(wù)器上訪問到自己規(guī)定的數(shù)據(jù):
修改根目錄
在 /etc/apache2/sites-available
中修改 000-default.conf
中的DocumentRoot /var/www/
修改為想要的目錄
比如:DocumentRoot /var/www/html/mainpage
執(zhí)行命令:
vim /etc/apache2/sites-available/000-default.conf
修改000-default.conf
中的DocumentRoot /var/www/
泄私,如下 ServerAdmin webmaster@localhost
http://10.11.53.202/%e7%88%b1%e5%bf%83/ DocumentRoot /var/www/html // 一般我們默認(rèn)為這個(gè)作為網(wǎng)站的根目錄,如果站點(diǎn)目錄不在/var/www下默認(rèn)是沒有權(quán)限的這是我們就要修改一下apache2下的apache2.conf文件了涕烧。打開apache2.conf
<Directory "/mnt/c/users/18451/Documents/study">
Options all
Require all granted
</Directory>
- 接下來重啟apache 即可
sudo apache2ctl -k restart