1.apache默認發佈文件
/var/www/html/index.html
2.apache配置文件
/etc/http/conf/httpd.conf ##主配置文件
/etc/http/conf.d/*.conf ##子配置文件
3.apache默認發佈目錄
/var/www/html
4.apache默認端口
80端口
二,apache基本配置
1.修改默認發佈文件
vim /etc/http/conf/httpd.conf
164 DirectoryIndex westos.html
systemctl restart httpd
2.修改默認發佈目錄
vim /etc/http/conf/httpd.conf
120 DocumentRoot "westos/www/test"
<Directory "westos/www/test">
Require all granted
</Directory>
systemctl restart httpd
3.apache的訪問設定
***設定IP的訪問***
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/admin"> ##允許所有人訪問admin目錄但拒絕240主機
Order Allow,Deny
Allow from All
Deny from 172.25.254.240
</Directory>
systemctl restart httpd
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/admin"> ##只允許240主機訪問admin目錄
Order Deny,Allow
Allow from 172.25.254.240
Deny from All
</Directory>
systemctl restart httpd
***設定用戶的訪問***
記着原密碼
htpassword -m /etc/httpd/accessuser admin
忘記原密碼
vim /etc/httpd/conf/httpd.conf
<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用戶訪問【二選一】
</Directory>
三,apache語言支持(php html cgi)
*****html*****
默認支持
*****php*****
[root@localhost html]# yum install php -y
Loaded plugins: langpacksrhel_dvd | 4.1 kB 00:00
Package php-5.4.16-21.el7.x86_64 already installed and latest version
Nothing to do
[root@localhost html]# systemctl restart httpd
測試:訪問172.25.254.240/index.php
*****cgi*****
[root@localhost html]# mkdir cgi
[root@localhost html]# ls
admin.html cgi index.php mysqladmin westos.html
[root@localhost html]# cd cgi
[root@localhost cgi]# vim index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
[root@localhost cgi]# vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
173 <IfModule dir_module>
174 DirectoryIndex index.cgi westos.html index.html
175 </IfModule>
[root@localhost cgi]# getenforce
Enforcing
[root@localhost cgi]# setenforce 0
[root@localhost cgi]# chmod +x index.cgi
[root@localhost cgi]# systemctl restart httpd
測試:訪問172.25.254.240/cgi
四,apache虛擬主機
apache虛擬主機可以讓我們的一臺apache服務器在被訪問不同域名的時候顯示不同主頁
*****服務端*****
[root@localhost ~]# cd /var/www
1.建立測試頁
[root@localhost www]# mkdir virtual/news.westos.com/html -p
[root@localhost www]# echo "<h1>news.westos.com's page" >virtual/news.westos.com/html/index.html
2.編寫配置文件
[root@localhost www]# cd /etc/httpd/conf.d
[root@localhost conf.d]# ls
autoindex.conf php.conf README userdir.conf welcome.conf
[root@localhost conf.d]# vim default.conf
<Virtualhost _default_:80> ##虛擬主機開啓的端口
DocumentRoot "/var/www/html" ##虛擬主機的默認發佈目錄
CustomLog "logs/default.log" combined ##虛擬主機日誌存放目錄
</Virtualhost>
[root@localhost conf.d]# vim news.conf ##指定域名news.westos.com的訪問到指定默認發佈目錄中
<Virtualhost *:80>
ServerName "news.westos.com"
DocumentRoot "/var/www/virtual/news.westos.com/html"
Customlog "logs/news.log" combined
</Virtualhost>
<Directory "/var/www/virtual/news.westos.com/html"> ##默認發佈目錄的訪問授權
Require all granted
</Directory>
[root@localhost conf.d]# systemctl restart httpd
*****測試端*****
[root@localhost conf.d]# vim /etc/hosts
172.25.254.240 news.westos.com www.westos.com
訪問:news.westos.com 或者 www.westos.com
五,https
https是HTTP的安全版,HTTPS的安全基礎是SSL,因此加密的詳細內容就需要SSL。
yum install crypto-utils -y
genkey www.westos.com ##
這個進度條完了還會有第二個進度條,此時在shell中輸入字符(隨意輸)直到進度條完
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
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</Virtualhost>
<Directory "/var/www/virtual/login.westos.com/html">
Require all granted
</Directory>
<Virtualhost *:80>
ServerName "login.westos.com"
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</Virtualhost>
#^(/.*)$ 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/login.westos.com
<h1>login.westos.com's page<h1>
vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex login.westos.com
測試:訪問login.westos.com時,其網址自動切換爲:https://login.westos.com