提示:此文章僅作為本人記錄日常學習使用,若有存在錯誤或者不嚴謹?shù)玫胤綒g迎指正。
一、在Ubuntu系統(tǒng)中安裝并配置Apache Http Server
Ubuntu系統(tǒng)版本:Ubuntu 20.04.5 LTS
1.1 安裝Apache
打開終端,輸入以下命令更新軟件包列表:
sudo apt update
安裝Apache服務(wù)器:
sudo apt install apache2
1.2 調(diào)整防火墻策略
查看相關(guān)程序的防火墻規(guī)則:
sudo ufw app list
此時應(yīng)該能看到以下結(jié)果:
允許Apache服務(wù)器的流量通過防火墻進行通信:
sudo ufw allow 'Apache'
查看 UFW 防火墻的狀態(tài)和配置信息:
sudo ufw status
如果你的防火墻已經(jīng)處于開啟狀態(tài),則可以看到以下結(jié)果:
如果防火墻未開啟,可以輸入以下命令以啟用防火墻后重復(fù)上述步驟:
1.3 檢查 Apache服務(wù)器
查看 Apache服務(wù)器的運行狀態(tài):
sudo systemctl status apache2
此時應(yīng)該能看到以下結(jié)果:
通過瀏覽器訪問以下地址來測試Apache HTTP Server是否安裝成功:
http://127.0.1.1
或者
http://localhost
如果看到Apache的默認頁面,則說明安裝成功:
1.4 添加自己的頁面
如果想要添加自己的頁面,你先要找到Apache服務(wù)器文件的位置:
cd /var/www/html
ls
可以看到這個index.html就是Apache的默認頁面:
首先,我們在/var/www/html下創(chuàng)建一個get_data.xml文件:
sudo vim get_data.xml
在get_data.xml文件中鍵入以下內(nèi)容:
<apps>
<app>
<id>1</id>
<name>Google Maps</name>
<version>1.0</version>
</app>
<app>
<id>2</id>
<name>Chrome</name>
<version>2.1</version>
</app>
<app>
<id>3</id>
<name>Goole Play</name>
<version>2.3</version>
</app>
</apps>
設(shè)置目錄所有者:
sudo chown -R $USER:$USER /var/www/html
設(shè)置目錄及其子文件的權(quán)限組:
sudo chmod -R 755 /var/www/html
創(chuàng)建配置文件my.conf:
sudo vim /etc/apache2/sites-available/my.conf
然后使用vim編輯my.conf文件并鍵入以下內(nèi)容:
<VirtualHost *:80>
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
啟用該配置文件my.conf:
sudo a2ensite my.conf
禁用在/etc/apache2/sites-available/000-default.conf文件中定義的默認站點:
sudo a2dissite 000-default.conf
測試配置是否生效:
sudo apache2ctl configtest
次時應(yīng)該可以看到如下輸出:
重啟Apache服務(wù)器:
sudo systemctl restart apache2
在瀏覽器中訪問http://localhost/get_data.xml或者http://127.0.1.1/get_data.xml地址,應(yīng)該可以看到我們剛才添加的文件:
1.5 相關(guān)命令
啟動Apache HTTP Server:
sudo service apache2 start
讓Apache HTTP Server在系統(tǒng)啟動時自動啟動:
sudo systemctl enable apache2
停止Apache HTTP Server:文章來源:http://www.zghlxwxcb.cn/news/detail-801124.html
sudo service apache2 stop
重新啟動Apache HTTP Server:文章來源地址http://www.zghlxwxcb.cn/news/detail-801124.html
sudo service apache2 restart
到了這里,關(guān)于【26】應(yīng)用開發(fā)——如何在Ubuntu系統(tǒng)中安裝并配置Apache Http Server的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!