一,PHP语言在apache中的测试
1,下载php软件包
[root@localhost html]# yum info php.x86_64
2,修改主配置文件
[root@localhost html]# vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>
DirectoryIndex index.php index.html <<<<添加把index.php放在前面,如果有index.php,就把这个作为默认发布页面,如果没有,那么把index.html作为默认发布页面
</IfModule>
注意:apache支持的php默认发布页面是index.php,这个可以在/etc/httpd/conf.d/php.conf里面查看
3,写一个index.php
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
index.html test.html westos
[root@localhost html]# vim index.php
<?php
phpinfo();
?>
4,重启网络,浏览器测试
二,cgi语言在apache的测试
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
index.html index.php test.html westos
[root@localhost html]# mkdir cgi <<<<<创建cgi的发布目录
[root@localhost html]# ls
cgi index.html index.php test.html westos
[root@localhost html]# cd cgi/
[root@localhost cgi]# vim index.cgi <<<<<写一个index.cgi页面
[root@localhost cgi]# cat index.cgi
#!/usr/bin/perl
print "Content-type:text/html\n\n"; <<<<<cgi要求必须要写这一行,不然会报错,本实验中网页打不开
print `date`;
[root@localhost cgi]# chmod +x index.cgi <<<<<cgi类似于脚本语言,需要加可执行权限
[root@localhost ~]# cd /etc/httpd/conf.d/
[root@localhost conf.d]# ls
autoindex.conf manual.conf php.conf userdir.conf
default.conf music.conf README welcome.conf
login.conf news.conf ssl.conf
[root@localhost conf.d]# vim default.conf <<<<<<修改配置文件,添加directory语句块
<VirtualHost _default_:80>
DocumentRoot /var/www/html
CustomLog "logs/default.log" combined
</VirtualHost>
<Directory "/var/www/html/cgi"> <<<<<<<设置默认发布目录
Options +ExecCGI <<<<<<<参数,执行cgi
AddHandler cgi-script .cgi <<<<<<<执行以cgi-script为名,或者以.cgi结尾的文件
DirectoryIndex index.cgi <<<<<<<指定默认发布页面
</Directory>
三,重启服务,浏览器测试
四,搭建论坛
1,安装LAMP架构所需的软件服务并启用
LAMP=linux+ Apache + Mysql + PHP|Python|Perl (rhel ,httpd,mariadb,php,php-mysql)
[root@localhost mnt]# mv /mnt/Discuz_X3.2_SC_UTF8.zip /var/www/html/ <<<<<论坛软件包
[root@localhost mnt]# cd /var/www/html/
[root@localhost html]# ls
cgi Discuz_X3.2_SC_UTF8.zip index.html index.php test.html westos <<<<<放在发布目录下
[root@localhost html]# unzip Discuz_X3.2_SC_UTF8.zip <<<<<解压
[root@localhost html]# ls
cgi index.html readme upload westos
Discuz_X3.2_SC_UTF8.zip index.php test.html utility
[root@localhost install]# chmod 777 /var/www/html/upload -R <<<<<给满权限,否则安装会有问题
[root@localhost install]# yum install php-mysql -y <<<<<安装所缺软件
[root@localhost install]# systemctl restart httpd.service <<<<<!!!!!重启httpd服务
2,浏览器输入172.25.254.100/upload开始安装,搭建完成。
五,Squid的正向代理
真机配置
1,真机可以上网,虚拟机无法上网
2,真机安装squid,修改配置文件
[root@foundation156 ~]# yum install squid -y
[root@foundation156 ~]# vim /etc/squid/squid.conf
56 http_access allow all <<<<<允许所有人通过
59 http_port 3128 <<<<<端口是3128
62 cache_dir ufs /var/spool/squid 100 16 256 <<<<<去掉注释
3,重启服务
[root@foundation156 ~]# systemctl start squid
虚拟机配置
1,配置浏览器代理
[root@localhost ~]# firefox &
Edit > Preferences > Advanced > Network > Settings > Manual proxy configuration > HTTP Proxy输入真机的ip
> Port 输入3128 >勾选 Use this proxy server for all protocols
2,虚拟机现在就可以成功上网了,这里的上网是指能打开网站,但是虚拟机本身ping 不通外网,因为虚拟机看到的页面都是真机缓存的,真机最多只能缓存100M,超过就会被清除。
六,反向代理
这里我们用三台主机来模拟访问腾讯的过程。西安的客户端访问西安服务器的本地缓存,西安服务器缓存深圳服务器的内容。
深圳主机(172.25.254.156)
[root@shenzheng ~]# rpm -qa | grep httpd <<<<<有Apache服务
httpd-2.4.6-17.el7.x86_64
httpd-tools-2.4.6-17.el7.x86_64
西安主机(172.25.254.100)
[root@xian ~]# yum install squid -y <<<<<<安装squid
[root@xian ~]# vim /etc/squid/squid.conf <<<<<<修改配置文件
http_access allow all <<<<<<允许所有人访问
# Squid normally listens to port 3128
http_port 80 vhost vport <<<<<<改为80端口,
cache_peer 172.25.254.147 parent 80 0 proxy-only <<<<<<父级是深圳主机,仅做代理
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256 <<<<<<去掉注释
这个可以在/usr/share/doc/squid-3.3.8/squid.conf.documented里面看
[root@xian ~]# systemctl restart squid <<<<<<重启squid服务
[root@xian ~]# systemctl stop firewalld <<<<<<关闭防火墙
[root@xian ~]# rpm -qa | grep http <<<<<<没有apache服务
[root@xian ~]# netstat -antlupe | grep 80 <<<<<<端口给squid,80给客户端访问
tcp6 0 0 :::80 :::* LISTEN 0 121938 7506/(squid-1)
udp 0 0 0.0.0.0:680 0.0.0.0:* 0 27261 940/rpcbind
udp6 0 0 :::680 :::* 0 27264 940/rpcbind
客户端
1,删除原来的浏览器代理!!!
2,SELINUX关闭
3,浏览器访问172.25.254.100,此时会显示172.25.254.156的index.html