網站首頁 編程語言 正文
1 Apache的作用
- 解析網頁語言,如html,php,jsp等
- 接收web用戶的請求,并給予一定的響應
2 Apache的安裝
安裝apche軟件:dnf install httpd.x86_64 -y
3 apache的啟用
- 開啟apache服務并設置開機啟動:
systemctl enable --now
httpd - 查看apache服務的狀態:
systemctl enable --now httpd
- 查看火墻信息:firewall-cmd --list-all 在火墻中永久開啟http服務:
firewall-cmd --permanent --add-service=http
- 在火墻中永久開啟https服務: f
irewall-cmd --permanent --add-service=https
- 在不改變當前火墻狀態的情況下刷新防火墻:
firewall-cmd --reload
4 apache的基本信息
apche的基本信息
- 服務名稱:
httpd
- 主配置文件:
/etc/httpd/conf/httpd.conf
- 子配置文件:
/etc/httpd/conf.d/*.conf
- 默認發布目錄:
/var/www/html
- 默認端口:80 (http) ,443(https)
- 日志文件:
/etc/httpd/logs
- 開啟apche服務后,輸入ip查看默認發布頁面:
(1)更改apche服務的端口號
- 查看httpd服務的默認端口號:
netstat -antlupe |grep httpd
- 編輯配置文件:
/etc/httpd/conf/httpd.conf
,修改端口號
- 重啟httpd服務:
systemctl restart httpd
- 查看httpd服務的端口號:
netsat -antlupe | grep httpd
- 更改端口號后,輸入ip后無法正常連接,原因是8080端口未添加在火墻中
- 在防火墻里添加888端口號:
firewall-cmd --permanent --add-port=888/tcp
- 在不改變當前火墻狀態的情況下刷新防火墻:
firewall-cmd --reload
- 輸入IP地址:端口號,可以正常訪問
(2)修改apche的默認發布文件
- 默認目錄:
cd /var/www/html
- 在文件默認發布目錄下新建一個文件
index.html
- 輸入:http://172.25.254.144查看
默認發布文件就是訪問apache時沒有指定文件名,即默認訪問的文件,此文件可以指定多個,但有訪問順序。
- 新建文件并編輯:
westo.html
- 編輯配置文件:
/etc/httpd/conf/httpd.conf
- 重啟httpd服務:
systemctl restart httpd
(3)修改apche的默認發布目錄
- 新建目錄:
mkdir -p /westos/html/
- 創建文件:
vim /westos/html/index.html
- 編輯apche配置文件:
/etc/httpd/conf/httpd.conf
- 重啟服務:
systemctl restart httpd
- 測試:瀏覽器中輸入http://172.25.254.144, 看到的是/westos/html/目錄內的默認發布文件
- 新建發布目錄:mkdir /var/www/html/westos
- 新建發布文件:vim /var/www/html/westos/index.html
- 編輯配置文件:vim /etc/httpd/conf/httpd.conf
- 重啟服務:
systemctl restart httpd
- 測試:
http://172.25.254.144/westos/
5 apache的訪問控制
5.1 基于客戶端ip的訪問控制
- 基于ip的訪問,規定了哪些ip可以訪問,那些ip不能訪問,其中配置文件中order中的deny和Allow哪一個順序在前直接決定了黑白名單的屬性
(1)白名單
- ip白名單:只有名單內的用戶可以訪問
- 編輯配置文件:
vim /etc/httpd/conf/httpd.conf
- 重啟服務:
systemctl restart httpd
- 測試: ip=172.25.254.44在ip白名單,可以正常訪問http://172.25.254.44/westos
ip=172.25.254.144的主機不在白名單內,無法訪問http://172.25.254.44/westos
(2)ip黑名單
- ip黑名單:只有名單內的用戶不可以訪問
- 編輯配置文件:
vim /etc/httpd/conf/httpd.conf
- 測試:ip=172.25.254.44在ip黑名單中,可以正常訪問http://172.25.254.44/westos
ip=172.25.254.144不在黑名單內,可以正常訪問http://172.25.254.44/westos
5.2 基于用戶認證的訪問控制
(1)允許部分用戶通過認證訪問共享目錄
- 生成認證文件,建立admin用戶:
htpasswd -cm /etc/httpd/htpasswdfile linux
- 建立linux用戶,-c會重新建立用戶認證文件,覆蓋之前的admin用戶,入密碼會覆蓋之前的用戶:
htpasswd -m /etc/httpd/htpasswdfile westos
- 只允許部分用戶可以通過認證,編輯配置文件:
vim /etc/httpd/conf/httpd.conf
- 重啟服務:systemctl restart httpd
- 測試:只有通過認證的用戶可以訪問共享目錄
(2)允許所有用戶通過認證訪問共享目錄
- 編輯配置文件:
vim /etc/httpd/conf/httpd.conf
- 重啟服務:
systemctl restart httpd
- 測試:所有用戶都可以通過認證訪問共享目錄
6 apache的虛擬主機
虛擬主機:在一臺真實主機上建立多個站點(多個域名),通過域名訪問一臺主機的不同網頁,從網絡地址看似乎有多個主機,這些主機被稱為虛擬主機
DNS解析域名的ip
建立linux,news,media的默認發布目錄: mkdir /var/www/westos.com/{linux,news,media} inux的默認發布文件: echo "<h1>hello linux</h1>" > /var/www/westos.com/news/index.html news的默認發布文件:echo "<h1>hello news </h1>" > /var/www/westos.com/news/index.html media的默認發布文件:echo "<h1>hello media </h1>" > /var/www/westos.com/media/index.html
- 新建apche的子配置文件并編輯:
/etc/httpd/conf.d/vhost.conf
- 編輯本地域名解析文件:
/etc/hosts
- 測試實驗效果:
7 apache的加密訪問
(1)安裝加密插件
- 查看apache的加密插件: dnf search apache
- 安裝加密插件
(2)生成私鑰: openssl genrsa -out /etc/pki/tls/private/www.westos.com.key
(3)生成證書簽名文件:openssl req -new -key /etc/pki/tls/private/www.westos.com.key -out /etc/pki/tls/cert/www.westos.com.csr
(4)生成證書:
openssl x509 -req -days 365 -in /etc/pki/tls/certs/www.westos.com.csr -signkey /etc/pki/tls/private/www.westos.com.key -out /etc/pki/tls/certs/www.westos.com.crt ## x509:證書格式 ## -req請求 ## -in加載簽證名稱 ## -signkey
- 編輯配置文件:
/etc/httpd/conf.d/ssl.conf
- 編輯apche的子配置文件并編輯:
/etc/httpd/conf.d/vhost.conf
- 重啟服務:
systemctl restart httpd
- 測試:此時就可以正常使用https加密服務
8 網頁重寫
在瀏覽器中輸入media.westos.com會自動跳轉到如下界面
- 如果要使輸入media.westos.com后跳轉到https://media.westos.com,可以通過網頁重寫實現,也就是當訪問http(80端口)時自動跳轉到https(443端口)
- 實現網頁重寫的步驟
(1)apche的子配置文件并編輯:/etc/httpd/conf.d/vhost.conf
(2)重啟服務:systemctl restart httpd
(3)測試,輸入域名后會自動加載https
9 正向代理
(1) 配置squid客戶端(該主機可以上網)
- 編輯配置文件:
/etc/squid/squid.conf
- 啟動squid服務:
systemctl start squid.service
(2)客戶端:在不能上網的主上測試,在瀏覽器中輸入:www.baidu.com不能訪問
- 加入代理:Preference——>Network settings——>Manual proxy configuration
- 填寫squid服務的主機和squid服務的端口號,設置完成后,該主機雖然沒有聯網但是可以通過代理訪問www.baidu.com及其他網站
- 在客戶端測試,能正常訪問www.baidu.com
但是在客戶端主機在仍然不能ping通www.baidu.com
10 反向代理
node1:沒有apache服務的虛擬機172.25.254.244
node2:能正常使用apache服務的虛擬機172.25.254.193,配置apache的發布文件
- 下載代理: dnf install squid -y
- 編輯配置文件:vim /etc/squid/squid.conf
- 重啟squid服務:systemctl restart squid
原本沒有apache服務的主機172.25.254.244可以通過172.25.254.193的80端口(http)緩存數據
11 apache 支持的語言
php
重啟apache服務:systemctl restart httpd.service
測試:http://172.25.254.144/index.php
cgi
mkdir /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
cd /var/www/html/cgi
chmod +x index.cgi
./var/www/html/cgi/index.cgi
測試:http://172.25.254.144/cgi/index.cgi
編輯虛擬主機的配置文件:vim /etc/httpd/conf.d/vhost.conf
重啟服務:systemctl restart httpd.service
測試:http://172.25.254.144/cgi/index.cgi
原文鏈接:https://blog.csdn.net/qq_41582883/article/details/109701895
相關推薦
- 2022-06-12 Python基于socket實現TCP客戶端和服務端_python
- 2022-10-20 Android?O實現Framework層CENTER鍵長按功能方法_Android
- 2022-12-08 C#?如何調用C++?dll?string類型返回_C#教程
- 2022-06-04 tomcat的catalina.out日志按自定義時間格式進行分割的操作方法_Tomcat
- 2022-06-26 Python基礎必備之語法結構詳解_python
- 2022-04-14 c語言的程序環境與預處理詳解_C 語言
- 2022-10-10 python讀取和保存為excel、csv、txt文件及對DataFrame文件的基本操作指南_py
- 2022-08-05 C語言庫函數qsort的使用詳解_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支