一、Apache默认支持的三种语言:html php cgi
1.默认支持html,不需要更改设置
2.设置支持php,访问php页面
cd /var/www/html
vim index.php
<?php
phpinfo();
?>
systemctl restart httpd
yum install php -y
cd /etc/httpd/conf.d #就会出现php.conf文件 默认发布文件
systemctl restart httpd
测试:在浏览器上访问index.php脚本就可以出现结果
3.设置支持cgi,访问cgi页面,一般用于用户注册
cd /var/www/html
mkdir cgi
cd /var/www/html/cgi
vim index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
chmod 755 index.gci 脚本要有执行权限
vim /etc/httpd/conf.d/a_default.conf
<Virtualhost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</Virtualhost>
<Directory "/var/www/html/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
systemctl restart httpd.service
测试:在浏览器上访问index.cgi脚本就可以出现结果
二、Apache签证制作
1.端口介绍:
http:80端口
https:443端口
2.HTTPS
http+ssl,在http应用层多了一层SSL,通俗的讲,就是客户端和服务端拥有一串没有第三者知道的密钥,通信时:用密钥解密得到的内容或者将内容加密发送给对方。
3.配置过程
yum install mod_ssl -y 安装mod_ssl 产生ssl.conf文件
cd /etc/httpd/conf.d 此目录里面多了一个ssl.conf文件
systemctl restart httpd
yum install crypoto-utils -y 制作证书,安装此软件
genkey www.xaut.com 为某个域名生成证书
过程:next-->选择大小-->next-->No-->next-->填写信息
vim ssl.conf
SSLCertificateFile /etc/pki/tls/certs/www.xaut.com.crt 将生成的证书和钥匙添加到此文件里面
SSLCertificateKeyFile /etc/pki/tls/private/www.xaut.com.key
systemctl restart httpd
4.测试
用https://www.xaut.com访问,就可以看到显示的证书是我们的制作的证书
三、网页重写:
1.什么是网页重写
输入某个域名主动跳到https访问
在网页上不是所有网址都是访问https,只有需要输入用户名密码的才会跳到https页面,所以我们可以制作一个域,只要是访问这个域,我们就主动跳转到https访问
2.文件配置
mkdir /var/www/virtual/login/html -p
cd /var/www/virtual/login/html
vim index.html
<h1>login</h1>
cd /etc/httpd/conf.d
cp news.conf login.conf
vim login.conf
<VirtualHost *:443>
ServerName login.xaut.com
DocumentRoot /var/www/virtual/login/html
CustomLog logs/login.log combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/www.xaut.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.xaut.com.key
</VirtualHost>
<Directory "/var/www/html/login/html">
Require all granted
</Directory>
<Virtualhost *:80>
ServerName login.xaut.com
RewriteEngine On 打开网页重写
RewiteRule ^(/.*)$ https://%{HTTP_HOST} $1 [redirect=301] 输入的地址前面自动加上https
</Virtualhost>
systemctl restart httpd
3.参数解释
^(/.*)$ :表示客户在浏览器上输入的全部字符
https:// :强制客户加密访问
%{HTTP_HOST} :客户请求主机
$1 :表示^(/.*)$的值
[redirect=301] :表示转换是临时的,302表示永久
4.测试
www.xaut.com 自动把地址变成 https://www.xaut.com