apache
企業常用的web服務,用來提供http://(超文本傳輸協議)
apache的安裝部署
yum install httpd -y
rpm -qc httpd ##尋找配置文件
yum install httpd-manual ##安裝manual
systemctl start httpd##火牆關掉阿帕其訪問
systemctl enable httpd
systemctl stop firewalld.service
systemctl disable firewalld.service
http://172.25.254.108
http://172.25.254.108/manual
apache的基礎信息
主配置目錄: /etc/httpd/conf
主配置文件: /etc/httpd/conf/httpd.conf
子配置目錄: /etc/httpd/conf.d/
子配置文件: /etc/httpd/conf.d/*.conf
默認發佈目錄: /var/www/html
默認發佈文件: index.html
默認端口: 80
默認安全上下文: httpd_sys_content_t
程序開啓默認用戶: apache
apache日誌: /etc/httpd/logs/*
修改默認端口
vim /etc/httpd/conf/httpd.conf
listen 8080 ##改爲8080
systemctl restart httpd
172.25.254.108:8080
修改默認發佈文件:
默認發佈文件就是訪問apache時沒有指定文件名稱時默認訪問的文件
這個文件可以指定多個,有先後順序
vim /etc/httpd/conf/httpd.conf
systemctl restart httpd
修改默認發佈目錄
mkdir -p /www/html
vim /www/html/index.html
/www/html/index.html
vim /etc/httpd/conf/httpd.conf
systemctl restart httpd
semanage fcontext -a -t httpd_sys_content_t ‘/www(/.*)?’ ##更改安全上下文
restorecon -RvvF /www/ ##同步
apache的虛擬機
mkdir /var/www/virtual/xiao.zhang.com/html -p
mkdir /var/www/virtual/xiao.li.com/html -p
vim /var/www/virtual/xiao.zhang.com/html/index.html
vim /var/www/virtual/xiao.li.com/html/index.html
cd /etc/httpd/conf.d
vim adefault.conf
vim xzhang.conf
ServerName xiao.zhang.com ##指定站點名稱
“/var/www/virtual/xiao.zhang.com/html” ##站點默認發佈目錄
combined ##站點日誌combined標誌四種日誌的集合
vim xli.conf
測試:
在測試主機中做好本地解析
vim /etc/hosts
172.25.254.108 xiao.zhang.com xiao.li.com www.want.com
apache內部訪問控制
1.針對主機訪問控制
vim adefault.conf
mkdir /var/www/html/test
vim /var/www/html/test/index.html
systemctl restart httpd
http://172.25.254.108/test/
2.用戶方式的訪問控制
htpasswd -cm /etc/httpd/userpass admin ##建立一個用戶
htpasswd -m /etc/httpd/userpass admin1 ##再次建立一個用戶
cat /etc/httpd/userpass ##查看用戶信息
cd /etc/httpd/conf.d
vim adefault.conf
mkdir /var/www/html/admin
vim /var/www/html/admin/index.html
systemctl restart httpd
http://172.25.254.108/admin/
apache支持的語言
vim /etc/httpd/conf/httpd.conf
1.html
2.php
vim /var/www/html/index.php
yum install php -y
systemctl restart httpd
http://172.25.254.108/index.php
3.cgi
mkdir -p /var/www/html/cgi
semanage fcontext -a -t httpd_sys_script_exec_t ‘/var/www/html/cgi(/.*)?’
restorecon -RvvF /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
chmod +x /var/www/html/cgi/index.cgi
/var/www/html/cgi/index.cgi
vim /etc/httpd/conf.d/a.conf
systemctl restart httpd
http://172.25.254.108/cgi/index.cgi
http://172.25.254.108/cgi/
https保護客戶數據傳輸不被破解
ss -antlupe | grep 443
yum install mod_ssl -y
yum install crypto-utils -y
genkey www.van.com ##至少1024,越大越慢
vim /etc/httpd/conf.d/ssl.conf
systemctl restart httpd
https://172.25.254.108/
設定https虛擬主機並設定網頁重寫
mkdir -p /var/www/virtual/next.door.com/html
vim /var/www/virtual/next.door.com/html/index.html
vim /etc/httpd/conf.d/next.conf
systemctl restart httpd
^(/.*)$
##客戶在瀏覽器地址欄輸入的所有字符
https://
##強制客戶加密訪問
%{HTTP_HOST}
##客戶請求主機
$1
##$1表示^的值
[redirect=301]
##訪問規則臨時轉換 302永久轉換
vim /etc/hosts
172.25.254.208 next.door.com
http://next.door.com