##########################
apache的安裝
yum install httpd -y ###安裝apache服務
systemctl start httpd ###開啟apache服務
systemctl stop firewalld ###關閉防火牆

#########################
apache的預設配置
1.apache的預設釋出檔案
index.html
2.apache的配置檔案
/etc/httpd/conf/httpd.conf ###主配置檔案
/etc/httpd/conf.d/*.conf ###其餘配置檔案
3.apache的預設釋出目錄
/var/www/html
4.apache的預設端口
80
############################
apache的基本配置
1.修改預設釋出檔案
編輯/etc/httpd/conf/httpd.conf 主配置檔案
<IfModule dir_module>
DirectoryIndex index.html ###預設釋出檔案為index.html
</IfModule>
2.修改預設釋出目錄
selinux狀态為enforcing
在配置檔案添加
#DocumentRoot "/westos/test"
<Directory "/westos/test">
Require all granted
</directory>
systemctl restart httpd ###重新開機服務
selinux狀态為disabled
systemctl restart httpd ###重新開機服務
semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?' ###修改目錄westos的安全上下文
3.apache的通路控制
黑白名單控制
vim /etc/httpd/conf/httpd.conf ###編輯主配置檔案
<Directory"/var/www/html/admin">
Order Allow,Deny ###allow和deny的順序 表示先讀allow再讀deny
Allow from all
Deny from x.x.x.x
</Directory>
表示允許所有拒絕172.25.254.78
密碼控制
htpasswd -cm /etc/httpd/accessuser mmm ###建立可以登陸的使用者及密碼(添加使用者時不加參數c)
vim /etc/httpd/conf/httpd.conf ###編輯配置檔案
<Directory "/var/www/html/admin">
AuthUserFile /etc/httpd/accessuser ###指定使用者及密碼認證檔案路徑
AuthName "please input username,passwd!!!" ###認證提示資訊
AuthType basic ###認證類型
Require valid-user ###認證使用者
4.apache語言支援
apache服務支援html php cgi 語言
html語言
預設支援語言
php語言
yum install php -y ###安裝php
vim /var/www/html/index.php
<?php
phpinfo(); ###php測試頁
?>
systemctl restart httpd ###重新開機服務
cgi語言
mkdir /var/www/html/cgi ###建立cgi目錄
vim /var/www/html/cgi/index.cgi ###寫cgi測試
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`; ###顯示日期
vim /etc/httpd/conf/httpd.conf ###編寫主配置檔案
<Directory "/var/www/html/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
systemctl restart httpd ###重新開機服務
########################
建立vartulhost
#######################
1.建立測試目錄
mkdir /var/www/virtual/1.test.com/html -p ###遞歸建立虛拟主機目錄
echo test > /var/www/virtual/1.test.com/html/index.html
2.配置
vim /etc/httpd/conf.d/default.conf ###編寫預設預設位址檔案
<Virtualhost _default_:80> ###虛拟主機開啟的端口
DocumentRoot "/var/www/html" ###虛拟主機釋出目錄
CustomLog "logs/defaulr.log" combined ###虛拟主機日志
</Virtualhost>
vim /etc/httpd/conf.d/test.conf
<Virtualhost *:80>
ServerName "1.test.com"
DocumentRoot "/var/www/virtual/1.test.com/html"
CustomLog "logs/test.log" combined
</virtualhost>
3.測試
編輯浏覽器所在主機/etc/hosts
172.25.254.116 www.westos.com 1.test.com
##############################
https
1.安裝ssl,crypto-utils
yum install ssl -y
yum install crypto-utils -y
genkey www.westos.com
下圖需要晃動滑鼠或敲鍵盤來生成密碼
vim /etc/httpd/conf.d/ssl.conf
vim /etc/httpd/conf.d/login.conf
mkdir /var/www/virtual/login.westos.com/html -p
echo login > /var/www/virtual/login.westos.com/html/index.html
在浏覽器所在主機中
vim /etc/hosts
login.westos.com