anpache的安裝
yum install httpd -y
systemctl start httpd
systemctl stop firewalld
systemctl enable httpd
systemctl disable 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.修改預設釋出檔案
vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex westos.html
systemctl restart httpd
2.修改預設釋出目錄
##當selinux是disable狀态
120 DocumentRoot "/westos/www/test"
<Directory "/westos/www/test">
Require all granted
</Directory>
##當selinux是enforcing狀态
systemctl restart httpd
semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'
restorecon -RvvF /westos
3.apache的通路控制
##設定ip的通路
<Directory "/var/www/html/admin">##允許所有人通路admin目錄但是拒絕250主機
Order Allow,Deny
Allow from All
Deny from 172.25.254.250
<Directory "/var/www/html/admin"> ##隻允許250主機通路admin目錄
Order Deny,Allow
Allow from 172.25.254.250
Deny from All
##設定使用者的通路
htpasswd -m /etc/httpd/accessuser admin
<Directory "/var/www/html/admin">
AuthUserFile /etc/httpd/accessuser##使用者認證檔案
AuthName "Please input your name and password !!"##使用者認證提示資訊
AuthType basic##認證類型
Require valid-user##認證使用者,認證檔案中所有使用者都可以通過
[Require user admin]##隻允許認證檔案中admin使用者通路,二寫一
4.apache語言支援
php html cgi
html語言預設支援
php語言
vim index.php
<?php
phpinfo();
?>
yum install php -y
cgi語言
mkdir /var/www/html/cgi
vim index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
<Directory "/var/www/html/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi
##################################
######## apache的虛拟主機 ########
1.定義
可以讓我們的一台apache伺服器在被通路不同域名的時候顯示
不同的首頁
2.建立測試頁
mkdir virtual/money.westos.com/html -p
mkdir virtual/news.westos.com/html -p
echo "money.westos.com's page" >virtual/money.westos.com/html/index.html
echo "news.westos.com's page" >virtual/news.westos.com/html/index.html
3.配置
vim /etc/httpd/conf.d/default.conf##位指定域名的通路都通路default
<Virtualhost_default_:80>##虛拟主機開啟的端口
DocumentRoot "/var/www/html"##虛拟主機的預設釋出目錄
CustomLog "logs/default.log" combined##虛拟主機日志
</Virtualhost>
vim /etc/httpd/conf.d/news.conf##指定域名news.westos.com的通路到指定預設釋出目錄中
<Virtualhost *:80>
ServerName "news.westos.com"
DocumentRoot "/var/www/virtual/news.westos.com/html"
CustomLog "logs/news.log" combined
<Directory "/var/www/virtual/news.westos.com/html">##預設釋出目錄的通路授權
Require all granted
4.測試
在浏覽器所在主機中
vim /etc/hosts
172.25.254.100www.westos.com news.westos.com
###############################
##### 網頁加密通路https #######
1.https定義
Hyper text transfer protocol over Secure socker layer
通過ssl
2.配置
yum install mod_ssl -y
yum install crypto-utils -y
genkey www.westos.com
/etc/pki/tls/private/www.westos.com.key
/etc/pki/tls/certs/www.westos.com.crt
vim /etc/httpd/conf.d/login.conf
<Virtualhost *:443>
ServerName "login.westos.com"
DocumentRoot "/var/www/virtual/login.westos.com/html"
CustomLog "logs/login.log" combined
SSLEngine on##開始https功能
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt#證書
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key ##密鑰
<Directory "/var/www/virtual/login.westos.com/html">
<Virtualhost *:80>##網頁重寫實作自動通路https
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
##########################################################################
####
## ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]##
##^(/.*)$客戶主機在位址欄中寫入的所有字元,不包含換行符##
##https://定向成為的通路協定##
##%{HTTP_HOST}客戶請求主機##
##$1$1的值就表示^(/.*)$的值##
##[redirect=301]臨時重定向 302永久重定向##
mkdir /var/www/virtual/login.westos.com/html -p
vim /var/www/virtual/login.westos.com/html/index.html
測試:
在客戶主機中添加解析
172.25.254.100 login.westos.com
通路http://login.westos.com 會自動跳轉到