apache:提供超文本传输协议
selinux=disabled
一、
安装服务
yum install httpd -y
查看端口
systemctl start httpd
netstat -antlupe | grep 80
netstat -antlupe | grep httpd
防火墙设置
systemctl stop firewalld
建立默认发布文件
cd /var/www/html/
vim index.html
<h1>lueluelue</h1>
浏览器输入172.25.254.108
二、修改端口
编辑http主配置文件,重启服务
vim /etc/httpd/conf/httpd.conf
42 Listen8080
systemctl restart httpd
由于改变了httpd的端口,浏览器查看时要加上端口
浏览器输入 172.25.254.108:8080
三、修改默认发布目录
建立目录
[root@localhost html]# mkdir /westos/html -p
[root@localhost html]# cd /westos/html/
vim index.html
jiayou!
编辑主配置文件,重启服务
修改默认发布目录
vim /etc/httpd/conf/httpd.conf
119 #DocumentRoot "/var/www/html" ##注释原默认目录
120 DocumentRoot "/westos/html"
121 <Directory "/westos">
122 require all granted
123 </Directory>
systemctl restart httpd
浏览器输入 172.25.254.108
四、修改默认发布文件
在/westos/html/下再建立一个html文件
vim test.html
hahaha
编辑主配置文件,重启服务
vim /etc/httpd/conf/httpd.conf
119 #DocumentRoot "/var/www/html"
120 DocumentRoot "/westos/html"
121 <Directory "/westos">
122 require all granted
123 DirectoryIndex test.html ##修改默认发布文件为test.html
124 </Directory>
systemctl restart httpd
浏览器输入 172.25.254.108/westos
五、基于IP的访问认证
通过命令对IP的访问认证进行限制
实验:
建立文件
cd /var/www/html/
mkdir westos
cd westos/
vim index.html:haochi
编辑主配置文件,重启服务
vim /etc/httpd/conf/httpd.conf
119 DocumentRoot "/var/www/html"
120 #DocumentRoot "/westos/html"
121
122 <Directory "/var/www/html/westos">
123 Order Allow,Deny
124 Allow from All
125 Deny from 172.25.254.108
126 </Directory>
systemctl restart httpd
输入浏览器访问172.25.254.108/westos
编辑主配置文件,重启服务
vim /etc/httpd/conf/httpd.conf
119 DocumentRoot "/var/www/html"
120 #DocumentRoot "/westos/html"
121
122 <Directory "/var/www/html/westos">
123 Order Deny,Allow
124 Allow from 172.25.254.108
125 Deny from All
126 </Directory>
systemctl restart httpd
浏览器输入 172.25.254.108/westos
六、基于用户的访问认证
通过命令对用户的访问认证进行限制
实验:
建立用户
cd /etc/httpd/
htpasswd -cm apacheuser admin ##新建用户
htpasswd -m apacheuser tom ##用户存在即不能使用-c新建
查看用户
cat apacheuser
编辑http主配置文件,重启服务
vim /etc/httpd/conf/httpd.conf
128 <Directory "/var/www/html/westos">
129 AuthUserFile /etc/httpd/apacheuser ##指定认证文件
130 AuthName "Please input user and password !!" ##认证语
131 AuthType basic ##认证类型
132 Require user admin ##指定admin用户登陆
133 # Require valid-user ##允许文件的所有用户登陆
134 </Directory>
systemctl restart httpd
输入浏览器访问172.25.254.108/westos
出现加密框,使用tom用户无法登陆
admin用户能通过认证
七、apache的虚拟主机
1个IP发布多个节点
实验:
添加可访问网址
vim /etc/hosts
172.25.254.108 www.westos.com music.westos.com news.westos.com
编辑默认配置文件
cd /etc/httpd/conf.d
vim default.conf
1 <VirtualHost _default_:80>
2 DocumentRoot /var/www/html
3 CustomLog "logs/default.log" combined
4 </VirtualHost>
建立虚拟主机的默认发布目录和文件
mkdir /var/www/virtual/westos.com/news -p
mkdir /var/www/virtual/westos.com/music -p
vim /var/www/virtual/westos.com/news/index.html:news
vim /var/www/virtual/westos.com/music/index.html:music
编辑news.conf配置文件
vim news.conf
1 <VirtualHost *:80>
2 ServerName news.westos.com
3 DocumentRoot "/var/www/virtual/westos.com/news/"
4 CustomLog "logs/news.log" combined ##所有日志的存放(访问,警告,拒绝)
5 </VirtualHost>
6 <Directory "/var/www/virtual/westos.com/news/">
7 Require all granted
8 </Directory>
编辑music.conf配置文件,重启服务
cp news.conf music.conf
vim music.conf:将news改为music
1 <VirtualHost *:80>
2 ServerName music.westos.com
3 DocumentRoot "/var/www/virtual/westos.com/music/"
4 CustomLog "logs/music.log" combined ##所有日志的存放(访问,警告,拒绝)
5 </VirtualHost>
6 <Directory "/var/www/virtual/westos.com/music/">
7 Require all granted
8 </Directory>
systemctl restart httpd
网页访问结果查看
浏览器输入www.westos.com music.westos.com news.westos.com
八、加密认证
安装加密服务,查看加密文件,重启httpd服务
yum install mod_ssl -y
ls /etc/httpd/conf.d
ststemctl restat httpd
安装服务
yum install crypto-utils -y
加密
genkey www.westos.com
Next-选择钥匙大小1024 Next-No-Next-填好信息Next
设置完后可以看到加密信息
编辑加密配置文件,将加密信息复制到配置文件中,重启服务
vim /etc/httpd/conf.d/ssl.conf
100 #SSLCertificateFile /etc/pki/tls/certs/localhost.crt
101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
108 #SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
109 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
systemctl restart httpd
浏览器输入:https://www.westos.com
下载证书后便可查看加密内容
获取加密内容后,查看加密内容信息
九、网页证书
访问login.westos.com时以443接口访问
添加可访问网址
vim /etc/hosts:172.25.254.108 login.westos.com
新建配置文件login.conf,编辑配置文件
cp news.conf login.conf
vim login.conf
1 <VirtualHost *:443> 第一段授权
2 ServerName login.westos.com
3 DocumentRoot "/var/www/virtual/westos.com/login/"
4 CustomLog "logs/login.log" combined
5 SSLEngine on
6 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
7 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
8 </VirtualHost>
9 <Directory "/var/www/virtual/westos.com/login/">
10 Require all granted
11 </Directory>
12 <VirtualHost *:80>
13 ServerName login.westos.com
14 RewriteEngine on
15 RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
16 </VirtualHost>
建立虚拟主机的默认发布目录和文件,重启服务
mkdir -p /var/www/virtual/westos.com/login
vim /var/www/virtual/westos.com/login/index.html:login
systemctl restart httpd
浏览器输入login.westos.com
下载证书
获得加密内容
十、Apache的CGI脚本
安装php服务
yum install php -y
建立php文件
cd /var/www/html/
vim index.php
1 <?php
2 phpinfo();
3 ?>
修改http主配置文件,修改默认发布文件,重启服务
vim /etc/httpd/conf/httpd.conf
180 DirectoryIndex index.php index.html
systemctl restart httpd
浏览器输入172.25.254.108查看
建立C语言文件
cd /var/www/html/
mkdir cgi
vim cgi/index.cgi
1 #!/usr/bin/perl
2 print "Contene-type: text/html\n\n";
3 print `date`;
赋予权限,运行C语言程序
chmod +x cgi/index.cgi
./cgi/index.cgi
编辑默认配置文件,重启服务
cd /etc/httpd/conf.d/
vim default.conf
systemctl restart httpd
浏览器输入172.25.254.108/cgi/index.cgi
十一、创建论坛
获得安装包,解压
给予权限
chmod 777 /var/www/html/upload -R
安装服务
yum install php-mysql -y
浏览器输入172.25.254.108/upload/install
按要求输入数据库密码和新建admin密码即可