yum install httpd -y安装
我首先重置了虚拟机。安装后启动httpd。此时无法使用。


关闭防火墙后,可以使用,不过由于默认发布目录为空,并不能显示界面。

生成共享文件 : vim /var/www/html/index.html
此时可以访问,并且看到内容。
httpd的访问控制

<Directory "/var/www/html/cq">
order deny,allow 顺序,意思时allow会覆盖掉deny策略
allow from 172.25.254.67 设置允许
deny from all 设置拒绝
</Directory>



cd /etc/httpd/conf
ls
htpasswd -cm cquser admin 创建访问用户
htpasswd -m cquser admin 再次创建
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/cq">
AuthUserFile /etc/httpd/conf/cquser
AuthType basic
AuthName "please input your name and password!"
Require user admin 仅仅允许这个用户输入密码登陆
</Directory>



阿帕奇的虚拟主机功能
注释掉之前的配置。
mkdir /var/www/virtual/newshtml
mkdir /var/www/virtual/music/html
vim /var/www/virtual/news/html/index.html
vim /var/www/virtual/music/html/index.html
cd /etc/httpd/conf.d/
vim a_default.conf
vim news.conf
vim music.conf
[root@cq conf.d]# cat a_default.conf
<Virtualhost default:80>
documentroot /var/www/html
customlog logs/default.log combined
</Virtualhost>
[root@cq conf.d]# cat news.conf
<Virtualhost> *:80>
servername news.westos.com
documentroot /var/www/virtual/av/html
customlog logs/news.log combined
</Virtualhost>
<Directory "/var/www/virtual/news/html">
require all granted
</Directory>
[root@cq conf.d]# cat music.conf
<Virtualhost> *:80>
servername music.westos.com
documentroot /var/www/virtual/music/html
customlog logs/music.log combined
</Virtualhost>
<Directory "/var/www/virtual/music/html">
require all granted
</Directory>
当这些配置完成之后,需要在浏览器一端设置本地域名解析。
vim /etc/hosts
172.25.254.103 www.westos.com news.westos.com music.default.com




最后systemctl restart httpd
总结一下这个思路:
首先呢,先注释掉上一个实验所添加的配置文件。
vim /etc/httpd/conf/httpd.conf
然后呢,我们需要建立虚拟主机。
首先
mkdir /var/www/virtual/news/html
mkdir /var/www/virtual/music/html
vim /var/www/virtual/news/html/index.html
vim /var/www/virtual/music/html/index.html
创建好虚拟主机目录,并且编辑好文件。
然后去配置文件。
vim /etc/httpd/conf.d/a_default.conf
vim /etc/httpd/conf.d/news.conf
vim /etc/httpd/conf.d/music.conf
那么这个配置文件是干什么用的呢?


a_default.conf 默认
<Virtualhost default:80>
documentroot /var/www/html 文件存放目录
customlog logs/default.log combined 日志记录文件
![]()
![]()
**所以说这个文件的意义就是 默认访问显示的内容,无论你在hosts里面怎样设置解析,都可以看到,从上图的实验可以看出。
music.conf
<Virtualhost> *:80> 80端口
servername music.westos.com 域名
documentroot /var/www/virtual/music/html文件目录
customlog logs/music.log combined 日志存放目录
</Virtualhost>
<Directory "/var/www/virtual/music/html">
require all granted 允许所有权限
</Directory>
linux上的cgi,php等
总体的思路是这样的:
关于php
首先yum install php -y 安装成功 服务器要关闭防火墙
然后编辑网页内容为php的测试页 vim /var/www/html/index.php
<?php
phpinfo();
?>
测试: 172.25.254.103/index.php


测试成功
关于cgi
yum install httpd-manual -y
mkdir /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print 'date';
chmod 755 index.cgi
然而此时访问却只能访问裸露的代码
此时需要配置 vim /etc/httpd/conf.d/a_default.conf
在manual页上复制
<Directory "/var/www/html/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
然后systemctl restart httpd 就成功了


关于https
yum install mod_ssl -y
yum install crypto-utils -y
genkey www.westos.com 生成证书 这个过程要注意进度条读完第一个选项是否
vim ssl.conf
crtl+z fg 1 复制锁和钥匙存的目录到这个配置文件里
systemctl restart httpd
此时访问 https://www.westos.com




但是此时的https不是自动的。
实现自动加锁
cd /etc/httpd/conf.d/
cp news.conf login.conf
vim login.conf
:%s/news/login
mkdir -p /var/www/virtual/login/html
vim /var/www/virtuyum isnal/login/html/index.html
vim /etc/httpd.conf/login.conf
sp /etc/httpd/conf.d/ssl.conf
复制钥匙复制锁
<Virtualhost *:443>
servername login.westos.com
documentroot /var/www/virtual/login/html
customlog logs/login.log combined
SSLEngine on
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
</Virtualhost>
<Directory "/var/www/virtual/login/html">
require all granted
</Directory>
<virtualhost :80>
servername login.westos.com
rewriteengine on
rewriterule ^(/.)1 [redirect=301]
</virtualhost>
systemctl restart httpd
测试;
访问 login.westos.com
结果自动加 https



:
网友评论