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