一.APACHE 基础信息
主配置目录: /etc/httpd/conf
主配置文件: /etc/httpd/conf/httpd.conf
子配置目录 :/etc/httpd/conf.d/
子配置文件 :/etc/httpd/conf.d/*.conf
默认发布目录: /var/www/html
默认发布文件: index.html
默认端口 :80
默认安全上下文:httpd_sys_content_t
程序开启默认用户: apache
apache日志: /etc/httpd/logs/*
二.apache部署:
1,配置网络
2,安装软件
yum install http.x86_64 -y ------对外提供超文本协议,提供web服务器
3,开启火墙策略(火墙开启的情况下)
图形界面:firewall-config
permanent-----http-https---options----reload firewalld(重新加载火墙服务)
systemctl strat httpd
systemctl enable httpd---开机自启动
![](https://i-blog.csdnimg.cn/blog_migrate/22b4aa4569dbdf125778e1a134c724e6.png)
查看: firewalld-cmd --list-all
![](https://i-blog.csdnimg.cn/blog_migrate/a0900056837891ce72558616e50c80da.png)
4,默认接口---80
netstate -antlupe | grep http
5,默认文件:vim index.html默认目录: /var/www/html/
6,安装手册: yum install httpr-manual
7,在默认目录下编写默认文件,发布内容则发生变化
cd /var/www/html
vim index.html
测试:
三.修改接口:
A.vim /etc/httpd/conf/httpd.conf
(42)Listen 8080
重新启动httpd
B.查看端口:netstat -antlupe | grep httpd
C.修改火墙策略
firewall-config
port---add--8080-add---6666--ok---options---reload
查看:firewalld-cmd --list-all
![](https://i-blog.csdnimg.cn/blog_migrate/c4b1cb35d99419878836af74064065e3.png)
D.网页访问:172.25.254.120:8080即可
![](https://i-blog.csdnimg.cn/blog_migrate/598d80e97768636cdaab0fced85602dc.png)
E.vim /etc/httpd/conf/httpd.conf
(42)Listen 6666
F.setenforce 0
systemctl restart httpd
![](https://i-blog.csdnimg.cn/blog_migrate/46db09bb2c85e9c81da79493e70313fa.png)
G.查看允许默认接口,,,可见没有6666
srmanage port -l | grep htp
![](https://i-blog.csdnimg.cn/blog_migrate/37a2466bc1768da557e2c5d5b4b8b690.png)
H.添加6666
semanage port -a -t http_port_t -p tcp 6666
![](https://i-blog.csdnimg.cn/blog_migrate/7616ace24ef0ee099b4959860fb4926e.png)
I.测试:
172.25.254.120:6666即可看到
四.修改默认发布文件
A.cd /var/www/html/
vim westos.html
![](https://i-blog.csdnimg.cn/blog_migrate/df87d11b8d5268254c2ea5e55b298d83.png)
B.systemctl restart httpd
![](https://i-blog.csdnimg.cn/blog_migrate/51f51588178b3177bdbf8ead2aff8b18.png)
C.修改配置文件默认的发布文件(可添加多个)
vim /etc/httpd/conf/httpd.conf
(164) westos.html
![](https://i-blog.csdnimg.cn/blog_migrate/c009e2939c9f5f14e3036877960ea7d0.png)
D.测试:172.25.254.120----显示的是westos.html 里面的内容
![](https://i-blog.csdnimg.cn/blog_migrate/8783e885ca906ace3900daa929302ef7.png)
E.倘若删除westo.html
则看到的是 /var/www/html/里面的内容
五.修改默认查看目录
A.新建一个目录
cd /var/www/html
mkdir /westos/web/html -p
B.vim /westos/web/html/westos.html
<h1>/westos/web/html's page</h1>
C.配置文件授权
vim /etc/httpd/conf/httpd.conf
注销119
120 DocumentRoot '/westos/web/html'
<Directory "/westos/web/html">
Require all granted (所有人可见)
</Directory>
systemctl restart httpd
SELINUX---开启
D.semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'
E.rstorecon -RvvF /westos/
![](https://i-blog.csdnimg.cn/blog_migrate/7bff1adb6286bb77a5c7b95e79a36d85.png)
测试:172.25.254.120
*********************************************************************
六.配置apache虚拟主机
cd /var/www/
mkdir westos.com/news/html -p
mkdir westos.com/music/html -p
设定两个文件可看内容
![](https://i-blog.csdnimg.cn/blog_migrate/9364110365d1578b5870b098198c162a.png)
A.vim westos.com/news/html/index.html
<h1> news's page</h1>
B.vim westos.com/music/html/index.html
<h1> music's page</h1>
编辑配置
![](https://i-blog.csdnimg.cn/blog_migrate/d2a2f603685eee09291d75cdf5711111.png)
cd /etc/httpd/conf.d/
1#vim a_default.conf
<VirtualHost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</VirtualHost>
2#vim news.conf
<VirtualHost *:80>
ServerName news.westos.com
DocumentRoot /var/www/westos.com/news/html 指定默认目录
CustomLog logs/news.log combined 指定日志---便于排错
</VirtualHost>
<Directory"/var/www/westos.com/news/html">
<指定访问地址名称news.westos.com----指定目录/var/www/westos.com/news/html>
Require all granted-----指定所有人可见
</Directory>
3#cp news.conf music.conf
vim music.conf
<VirtualHost *:80>
ServerName music.westos.com
DocumentRoot /var/www/westos.com/music/html
CustomLog logs/music.log combined
</VirtualHost>
<Directory"/var/www/westos.com/music/html">
Require all granted
</Directory>
![](https://i-blog.csdnimg.cn/blog_migrate/70e811d36e8c0ef81c664555ed1dad83.png)
4,systemctl restart httpd
5.
本地解析---主机添加
vim /etc/hosts
测试:
七.apache访问控制
1,基于IP方式
#cd /etc/httpd/conf.d/
vim a_default.conf
![](https://i-blog.csdnimg.cn/blog_migrate/a5e007bacc73a81149582b69c3f961c2.png)
<Directory "/var/www/html">
Order Allow,Deny(谁在前先读取谁)
Allow from all
Deny from 172.25.254.220不允许220访问(先允许全部,再拒绝220)
</Directory>
systemctl restart httpd
20访问正常,
2,基于用户
A。创建认证文件
htpasswd -cm http_userlist admin
![](https://i-blog.csdnimg.cn/blog_migrate/b746308363c2a2689c4e2a14789a30e6.png)
文件存在后,不加c
htpasswd -m http_userlist admin1
![](https://i-blog.csdnimg.cn/blog_migrate/bb2534467ef80100f0f742881bf57015.png)
B。
vim a_default.conf
前面ip注释掉
<Directory "/var/www/html">
AuthUserFile /etc/httpd/conf.d/http_userlist---用指定文件做认证
AuthName "Plase input username and passwd !!!"--用户可看到的标题
AuthType basic---认证类型--基本认证。有密码即可
#Require user admin
Require vaild-user----指定可通过认证用户
</Directory>
![](https://i-blog.csdnimg.cn/blog_migrate/358050fe99e8abd4a71c597f65f811de.png)
清除内存:
C,ctrl+shift----everything
测试;
八.apache支持语言
《一》PHP
1.cd /var/www/html
vim index.php
![](https://i-blog.csdnimg.cn/blog_migrate/e1f00d8fd3b29a714991b428f575ee83.png)
<?php
phpinfo()
?>
2.yum install php -y
![](https://i-blog.csdnimg.cn/blog_migrate/bbb9fcab627637cedd246f9be82fa2d9.png)
php -a 可进入,说明安装成功
测试:172.25.254.120/index.php
《二》接口语言---cgi---通用网关接口
1.mkdir -p /var/www/html/cgi
2.semanager fcontent -a -t httpd_sys_script_exec_t '/var/www/html/cgi(/.*)?'
![](https://i-blog.csdnimg.cn/blog_migrate/ed437563c72284ae232971e8e18d53b0.png)
3.restorecon -RvvF /var/www/html/cgi/
刷新SELINUX
cd /var/www/html
4.vim cgi/index.cgi
![](https://i-blog.csdnimg.cn/blog_migrate/5f59990971e612b3c4eca47a35ec3142.png)
#!usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
![](https://i-blog.csdnimg.cn/blog_migrate/9812762f3854116c0fdca12ddafcf904.png)
5.cd /etc/httpd/conf.d/
vim a_default.conf
<Directory"/var/www/html/cgi">
Options ExecCGI
AddHandler cgi-script .cgi
</Directory>
![](https://i-blog.csdnimg.cn/blog_migrate/28f8b3dae7b522cfe4f27b8e6ef3b0f5.png)
6.chmod +x /var/www/html
![](https://i-blog.csdnimg.cn/blog_migrate/fd9519eff068f0b7b15febadbeb33e8b.png)
测试:
172.25.254.120/cgi/index.cgi
《三》执行python语言
1.cd /var/www/
cd cgi-bin
rm -fr index.cgi
2.python webapp.wsgi 告诉系统webapp.wsgi是python语言
3.chmod +x webapp.wsgi 可执行权限
![](https://i-blog.csdnimg.cn/blog_migrate/5f9bb5970f3c98bc4a942d6b68797b0a.png)
4.yum install mod_wsgi.x86_64
![](https://i-blog.csdnimg.cn/blog_migrate/da8e142ff741b71454236fba4c75a007.png)
5.systemctl restart httpd
6.vim webapp.conf
![](https://i-blog.csdnimg.cn/blog_migrate/9d71298e23190172e47392f95b05f0b5.png)
<VirtualHost *:80>
ServerName webapp.westos.com
DocumentRoot /var/www/cgi-bin
CustomLog logs/webapp.log combined
WSGIScriptAlias / /var/www/cgi-bin/webapp.wsgi
</VirtualHost >
主机
vim /etc/hosts/
加上 webapp.westos.com
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
测试;
九.加密访问
1.yum install mod_ssl -y
![](https://i-blog.csdnimg.cn/blog_migrate/b8046377298f3123e5ccbc5b88bbcddd.png)
2.yum install crypto-utils -y
3.genkey www.westos.com
next---1024---next
选择no
4.vim /etc/httpd/conf.d/ssl.conf
101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
109 SSLCertificateKeyFile /etc/pki/tls/private/
![](https://i-blog.csdnimg.cn/blog_migrate/c0931e31a66147f2b2c71497b103fbce.png)
5,测试:
https:172.25.254.120
查看信息,是自己修改的内容
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
十.网页重写
一.制作一个虚拟主机
cd /var/www/
cd westos.com/
mkdir login
mkdir login/html
![](https://i-blog.csdnimg.cn/blog_migrate/9292707dca3b6c564f776fcfc7fa9ed5.png)
vim login/html/index.html
<h1>login's page</h1>
![](https://i-blog.csdnimg.cn/blog_migrate/4d1ef90d759535ef2e81a5753160dd7e.png)
二。网页重写
cd /etc/httpd/conf.d/
cp news.conf login.conf
![](https://i-blog.csdnimg.cn/blog_migrate/58f26a8e4b4c4cb8c5e669423e2db349.png)
vim login.conf
1 <VirtualHost *:443>
2 ServerName login.westos.com
3 DocumentRoot /var/www/html/virtual/login.westos.com/html
4 CustomLog "logs/login.logs" 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/html/virtual/login.westos.com/html">
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>
![](https://i-blog.csdnimg.cn/blog_migrate/85aaaa90af4e62c36d13aa401c6d6476.png)
^(/.*)$ :客户在浏览器地址栏中输入的所有字符
ttps:// #强制客户加密访问
%{HTTP_HOST} #客户请求主机
$1 # ‘$1标示^(/.*)$的值’
[redirect=301] #临时重写 301为永久转换
测试
补充知识:
两种架构:
LAMP=linux + apache + mariadb + php
LAMP=linux + apache + mariadb + php/perl/python
十一.BBS论坛
cd /var/www/
cd /etc/http.conf.d/
cp news.conf bbs.conf
![](https://i-blog.csdnimg.cn/blog_migrate/ac2bd73f5c3d5dc0bc16453e26c4a918.png)
1. vim bbs.conf
![](https://i-blog.csdnimg.cn/blog_migrate/ce30557707db25ea7c83f9a5cd2e031f.png)
<VirtualHost *:80>
ServerName bbs.westos.com
DocumentRoot /var/www/westos.com/bbs/html
CustomLog logs/bbs.log combined
</VirtualHost>
<Directory "/var/www/westos.com/bbs/html">
Require all granted
</Directory>
![](https://i-blog.csdnimg.cn/blog_migrate/2c9aeb7eb8abe6c88e622e56a839da5b.png)
2. systemctl restart httpd
3.mkdir /var/www/westos.com/bbs/html -p
cd /var/www/westos.com/bbs/html
![](https://i-blog.csdnimg.cn/blog_migrate/89726e45271aa5000f253483558ee7c4.png)
4. unzip Discuz_X3.2_SC_UTF8.zip
![](https://i-blog.csdnimg.cn/blog_migrate/ef83a199ac5afbf0108295e5817965dc.png)
5. rm -fr Discuz_X3.2_SC_UTF8.zip
![](https://i-blog.csdnimg.cn/blog_migrate/f04b9c722000c616bd15eabc42062738.png)
cd /var/www/westos.com/bbs/html
cd upload/
6. chmod -R 777 config
![](https://i-blog.csdnimg.cn/blog_migrate/1bf8e7705c419ca3ad6c2ca7412866fa.png)
7. chmod -R 777 data
8. systemctl restart httpd
9. setenforce 0
cd upload/
![](https://i-blog.csdnimg.cn/blog_migrate/91ab6fa195ea279b1fd3cb0dddf8b4a8.png)
10. chmod 777 uc_client uc_server -R
11. yum install mariadb-server -y
![](https://i-blog.csdnimg.cn/blog_migrate/b321964efbefae0f10e1de31cab7e50a.png)
12. systemctl start mariadb
13. systemctl enable mariadb
![](https://i-blog.csdnimg.cn/blog_migrate/314dbe5572eda351834215475d8be7bb.png)
14. vim /etc/my.cnf
( 10) skip-networking=1
![](https://i-blog.csdnimg.cn/blog_migrate/0ee0d16cfcce3598b9f6c39e59d4efa7.png)
15. systemctl restart mariadb
16.netstat -atnlupe | grep mysql
17.mysql_secure_installation
![](https://i-blog.csdnimg.cn/blog_migrate/7f9be9b7f03a9865d7f69a8b808c4848.png)
18 yum install php-mysql.x86_64 -y
![](https://i-blog.csdnimg.cn/blog_migrate/a7d25a02c488934641ec0e2d7bd37f37.png)
systemctl restart httpd
主机测试ho
vim /etc/hosts
论坛制作安成
十二.CDN加速=CONTENT DELIVERY NETWORK 内容发布网络
squid ---软件用于翻墙
此实验172.25.254.120----用于客户端
172.25.254.220---用于服务端
服务端:
1.下载squid
yum install squid -y
![](https://i-blog.csdnimg.cn/blog_migrate/3fe32058f8db6d8308707f4dc8f6b615.png)
2.systemctl start squid
3.vim /etc/squid/squid.conf
![](https://i-blog.csdnimg.cn/blog_migrate/170189eb075dbe48e6be2bd2ad32d310.png)
(56)http_access allow all
(62)去掉注释
![](https://i-blog.csdnimg.cn/blog_migrate/2d5406436a70a4c78e4d62feaab9c20f.png)
4.systemctl restart squid
5.systemctl syop firewalld
客户端:
本不可以上网设定:翻墙
1.打开firefox
2.edit---perferance---advanced-----network---settings---manual pro---
http proxy---172.25.254.220(服务端ip)---port---3128
-----use this -----ok便可浏览百度信息
关闭翻墙
edit---perferance---advanced-----network---settings----no proxy
![](https://i-blog.csdnimg.cn/blog_migrate/6d70adbb53419fa2a980a7583c5efe28.png)
*******************************************************************
十三.反向代理
服务端
vim /etc/squid/squid.conf
(59)http_port 80 vhost vport
虚拟端口 虚拟域名
cache_peer 172.25.254.120 parent 80 0 proxy-only
当你访问80端口时,我用100 的80端口做代理
systemctl restart squid
主机端
vim /etc/hosts
172.25.254.220
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
十四.轮循
服务端口:
vim /etc/squid/squid.conf
(60)cache_peer 172.25.254.120 parent 80 0 proxy-only name=web1 round-robin
(60)cache_peer 172.25.254.130 parent 80 0 proxy-only name=web2 round-robin
cache_peer_domain web1 web2 www.westos.com
systemctl restart squid
客户端
主机测试
www.westos.com
120 和130的默认文件交相实现
8*******************************************************************
十五,权重
weght=N
服务端口:
vim /etc/squid/squid.conf
(60)cache_peer 172.25.254.120 parent 80 0 proxy-only name=web1 round-robin weight=2
(60)cache_peer 172.25.254.130 parent 80 0 proxy-only name=web2 round-robin
cache_peer_domain web1 web2 www.westos.com
systemctl restart squid
客户端
主机测试
www.westos.com
120 和130的默认文件交相实现,120出现两次130出现一次