####apache服务(二)####
1.网页重写与虚拟主机的https
[[email protected] html]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# firewall-cmd --permanent --add-service=http
success
[[email protected] conf.d]# firewall-cmd --permanent --add-service=https
success
[[email protected] conf.d]# firewall-cmd --reload
success
[[email protected] conf.d]# vim music.conf
<Virtualhost *:80>
Servername music.westos.com
RewriteEngine on 允许网页重写
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301] ##重写为https
</Virtualhost>
<Directory "/var/www/virtual/music.westos.com/html">
Require all granted ##授权
</Directory>
<Virtualhost *:443> ##443端口
Servername music.westos.com
Documentroot /var/www/virtual/music.westos.com/html
Customlog "logs/default-443.log" combined ##产生的日志放在logs/default-443.log 下
SSLEngine on ##开启认证
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt ##证书
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key ##钥匙
</Virtualhost>
[[email protected] conf.d]# vim news.conf
<Virtualhost *:80>
Servername news.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</Virtualhost>
<Directory "/var/www/virtual/news.westos.com/html">
Require all granted
</Directory>
<Virtualhost *:443>
Servername news.westos.com
Documentroot /var/www/virtual/news.westos.com/html
Customlog "logs/news-443.log" combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</Virtualhost>
[[email protected] conf.d]# systemctl restart httpd
测试机操作
[[email protected] ~]# vim /etc/hosts
172.25.254.109 www.westos.com westos.com news.westos.com music.westos.com
打开firefox输入http://music.westos.com 会自动跳转为https://music.westos.com.
php
[[email protected] html]# vim index.php
<?php
phpinfo ();
?>
[[email protected] html]# vim /etc/httpd/conf/httpd.conf ##编辑配置文件在163行添加index.php
163 DirectoryIndex index.php index.html ##apache默认读取的文件是index.php
[[email protected] html]# chmod +x /var/www/html ##给/var/www/html添加执行权限
[[email protected] html]# systemctl restart httpd.service ##重启服务
2.cgi通用网管接口
[[email protected] html]# mkdir cgi ##建立cgi目录
[[email protected] html]# yum install http-manual -y ##下载http手册
[[email protected] html]# cd cgi/
[[email protected] cgi]# vim index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
[[email protected] html]# cd /etc/httpd/conf.d/
[[email protected] conf.d]# vim default.conf
<Virtualhost _default_:80>
DocumentRoot /var/www/html
Customlog "logs/default.log" combined
</Virtualhost>
<Directory "/var/www/html">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
[[email protected] conf.d]# chmod +x /var/www/html/cgi/*
[[email protected] conf.d]# semanage fcontext -a -t httpd_sys_script_exec_t ‘/var/www/html/cgi/(/.*)?‘ ##设置安全上下文
[[email protected] conf.d]# restorecon -RvvF /var/www/html/cgi/ ##刷新标签
[[email protected] conf.d]# systemctl restart httpd.service ##重启httpd服务
论坛
[[email protected] html]# yum install mariadb -y 安装数据库
若没有安装数据库,安装后要进行安全设置。因为一般情况下我们不会把数据库的端口裸露在外,所以要隐藏端口。
[[email protected] html]# vim /etc/my.cnf
10 skip-networking=1 ##隐藏数据库端口
[[email protected] html]# netstat -antlpe | grep mariadb ##查看数据库开放端口
[[email protected] html]# setenforce 0 ##selinux改为警告模式
[[email protected] html]# systemctl start mariadb ##开启数据库
下载论坛安装包
Discuz_X3.2_SC_UTF8.zip
[[email protected] html]# unzip Discuz_X3.2_SC_UTF8.zip
解压后进入
[[email protected] html]# chmod 777 upload/ -R
接下来进入到到浏览器按照提示进行操作。
suqid 正向代理
当你所在的主机不能访问到你所访问到的内容时,可以设置一个代理服务器,这个代理服务器上必须有你所需要的内容,这是你就可以通过代理主机
squid反向代理服务
在操作前要先卸载httpd服务,我们这台机子作为代理服务器,
[[email protected] conf.d]# yum install squid -y
[[email protected] conf.d]# systemctl start squid
[[email protected] conf.d]# vim /etc/squid/squid.conf
56 http_access allow all
59 http_port 80 vhost vport
60 cache_peer 172.25.254.3 parent 80 0 no-query originserver round-robin name=w eb1
61 cache_peer 172.25.254.4 parent 80 0 no-query originserver round-robin name=w eb2
62 cache_peer_domain web1 web2 www.bili.com
## 配置文件中添加的内容在/usr/share/doc/squid-3.3.8/squid.conf.documented 中都有)
[[email protected] conf.d]# systemctl restart squid