我的https服务已经搭建好了,但是却无法在输入网址后自动转为更加安全的https访问协议,那如何才能实现普通访问自动转换加密访问方式?
HTTPS虚拟主机及网页重写
虚拟主机:
1. 进入/var/www/westos.com目录下,创建目录/login/htm
[root@apache-server conf.d]# cd /var/www/westos.com/
[root@apache-server westos.com]# mkdir -p login/html
2. 在该目录下建立虚拟主机的访问文件
[root@apache-server html]# pwd
/var/www/westos.com/login/html
[root@apache-server html]# vim index.html
[root@apache-server html]# cat index.html
<h1>login's page</h1>
3. 编辑主配置文件
[root@apache-server html]# cd /etc/httpd/conf.d
[root@apache-server conf.d]# vim login.conf
<VirtualHost *:443>
SSLEngine on
ServerName login.westos.com
DocumentRoot /var/www/westos.com/login/html
CustomLog logs/login.log combined
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</VirtualHost>
<Directory "/var/www/westos.com/login/html">
Require all granted
</Directory>
网页重写:
继续编辑虚拟主机的配置文件:
[root@apache-server conf.d]# vim login.conf
添加:
<VirtualHost *:80>
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost>
参数解释:
^(/.*)$ 客户在浏览器地址栏中输入的所以字符
https:// 强制客户加密访问
%{HTTP_HOST} 客户请求主机
$1 $1表示 ^(/.*)$的值
[redirect=301] 永久重写 302临时转换
重新启动服务
[root@apache-server conf.d]# systemctl restart httpd.se
rvice
测试:
在测试端的主机添加相应的解析信息
[root@foundation68 ~]# vim /etc/hosts
172.25.254.102 www.westos.com music.westos.com news.westos.com login.westos.com
搭建论坛(bbs.westos.com)
1. 创建发布目录
进入/var/www/westos.com目录下,创建目录/bbs/htm
[root@apache-server conf.d]# cd /var/www/westos.com/
[root@apache-server westos.com]# mkdir -p bbs/html
将主机上的搭建论坛的安装包传送到服务端的发布目录下
[root@apache-server westos.com]# cd bbs/html/
[root@apache-server html]# scp root@172.25.254.68:/home/kiosk/Desktop/Discuz* .root@172.25.254.68's password:
Discuz_X3.2_SC_UTF8.zip 100% 12MB 11.9MB/s 00:00
将安装包解压:
[root@apache-server html]# unzip Discuz_X3.2_SC_UTF8.zip
解压后会出现3 个文件
[root@apache-server html]# ls
Discuz_X3.2_SC_UTF8.zip readme upload utility
2. 编写子配置文件bbs.conf
[root@apache-server conf.d]# vim bbs.conf
[root@apache-server conf.d]# cat bbs.conf
<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>
3. 查看论坛的搭建步骤
[root@apache-server conf.d]# cd /var/www/westos.com/bbs/html/
[root@apache-server html]# ls
Discuz_X3.2_SC_UTF8.zip readme upload utility
[root@apache-server html]# cd readme/
[root@apache-server readme]# ls
changelog.txt convert.txt license.txt readme.txt upgrade.txt
[root@apache-server readme]# less readme.txt
4 . 接下来提示步骤进行论坛的搭建:
(1)进入/var/www/westos.com/bbs/html/upload
(2)给config和data目录添加权限(注意要加-R参数,表示递归)
[root@apache-server upload]# chmod -R 777 config
[root@apache-server upload]# chmod -R 777 data
(3)给uc_client 和 uc_server 目录添加权限
[root@apache-server upload]# chmod -R 777 uc_client/ uc_server/
(4)在服务端将selinux的状态修改为警告模式
(5)安装mariadb-server 和 php-mysql 安装数据库和数据库插件
[root@apache-server html]# yum install mariadb-server.x86_64 php-mysql.x86_64 -y
开启数据库:
[root@apache-server upload]# systemctl start mariadb
[root@apache-server upload]# systemctl enable mariadb
ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'
对数据库的安全性进行设置:
关闭网络接口:
//写入:skip-networking=1
安全初始化:
(6)重新启动服务
[root@apache-server upload]# systemctl restart httpd.service
(7)打开浏览器输入bbs.westos.com/upload/install进入安装向导
可以在右上角输入管理员用户名和信息进行登录