我的linux主机的ip为172.16.29.2,系统为centos7.2。使用centos6的操作内容可能不同,主要是因为两个,一个是数据库,centos7使用的数据库是mariadb,6使用的是mysql;二是httpd程序不同,并且两个版本变化很大。写这个博客之前本来打算写一个脚本自动化实现,写的中间的时候发现需要更改的内容有些需要借用网络传输一些文件,并且通用性比较差,就整理了一下把脚本拆分组织了一下语言写了这个博客。有一个写到一半的脚本我也贴到文章的附件内,有兴趣可以看看。
之所以要https是因为全站https正在流行开来。
1 环境准备
1
2
3
|
setenforce 0
#关闭selinux
iptables -F
#关闭防火墙
yum
install
mariadb-server httpd phpphp-mysql unzip php-mbstring mod_ssl -y
|
安装各种组件,组件按顺序分别是数据库,Apache,php,php连接数据库组件,linux解压zip文件的工具,phpMyAdmin需要的组件,加密组件
2文件准备
1
2
3
4
5
6
|
wget http:
//download
.comsenz.com
/DiscuzX/3
.2
/Discuz_X3
.2_SC_UTF8.zip
#下载
wget https:
//files
.phpmyadmin.net
/phpMyAdmin/4
.6.5.2
/phpMyAdmin-4
.6.5.2-all-languages.zip
#下载
mkdir
/www
#创建文件夹
unzip phpMyAdmin-4.6.5.2-all-languages.zip-d
/www
#解压
unzip Discuz_X3.2_SC_UTF8.zip -d
/www/discuz/
#解压
chown
-R apache:apache
/www
#更改权限
|
3数据库
1
|
systemctl start mariadb.service
#开启数据库
|
接下来是一键建库
1
2
3
4
5
6
7
8
|
mysql <<eof
create database dcdb;
create database weblog;
use weblog;
create table apachelog(ID int not nullprimary key,DATE varchar(100),LOGCONTENT text);
grant all privileges on dcdb.* todcuser@
'%'
identified by
"oldking"
;
grant all privileges on *.* to admin@
'%'
identifiedby
"oldking"
;
eof
|
4 生成证书
这部分内容我写的不是很全,可以产考我之前的博客
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
http:
//oldking
.blog.51cto.com
/10402759/1882421
cd
/etc/pki/CA/
touch
index.txt
echo
01 > serial
(
umask
066;openssl genrsa -outprivate
/cakey
.pem 2048)
#生成ca的私钥
openssl req -new -x509 -keyprivate
/cakey
.pem -out cacert.pem
#ca自签证书,把这个证书改名为.crt结尾,导入浏览器就可使用了
cd
/etc/httpd/
mkdir
ssl
cd
ssl/
(
umask
066;openssl genrsa -out httpd.key2048; )
#http服务的私钥
openssl req -new -key httpd.key -outhttpd.csr -days 365
#生成证书
cd
/etc/pki/CA/
openssl ca -
in
/etc/httpd/ssl/httpd
.csr -outcerts
/httpd
.crt -days 700
cp
certs
/httpd
.crt
/etc/httpd/ssl/
|
5配置phpMyAdmin
1
2
3
4
5
|
cd
/www/
vim phpMyAdmin-4.6.5.2-all-languages /.htaccess
#添加以下内容,实现http协议的内容转发到https上,现在很流行全站https
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$https:
//
%{SERVER_NAME}%{REQUEST_URI} [L,R]
|
以下的配置是配置phpMyAdmin管理的数据库和账号密码
1
2
3
4
|
vim
/www/
phpMyAdmin-4.6.5.2-all-languages
/libraries/config
.default.php
$cfg[
'Servers'
][$i][
'host'
] =
'172.16.29.2'
;
$cfg[
'Servers'
][$i][
'user'
] =
'admin'
;
$cfg[
'Servers'
][$i][
'password'
] =
'oldking'
;
|
6 配置httpd添加两个虚拟主机
这里我使用一键配置命令,注意ip,现在基本上所有网站都在使用压缩传输
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
cat
>
/etc/httpd/conf
.d
/vhost
.conf<<eof
<VirtualHost 172.16.29.2:80>
ServerAdminwebmaster@dummy-host.example.com
DocumentRoot
/www/discuz/upload
#网站路径
ServerName bbs.oldking.org
#网站名称
ErrorLoglogs
/oldking
.bbs-error_log
#错误日志的位置
CustomLoglogs
/oldking
.bbs-access_log common
#访问日志的位置
<Directory
"/www/discuz/upload"
>
Options None
AllowOverride None
Require all granted
#以下三行是实现压缩传输的
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATEtext
/html
text
/plain
text
/css
text
/xml
text
/javascript
BrowserMatch
"^Mozilla/2"
no-
gzip
<
/Directory
>
<
/VirtualHost
>
<VirtualHost 172.16.29.2:80>
ServerAdminwebmaster@dummy-host.example.com
DocumentRoot
/www/phpMyAdmin-4
.6.5.2-all-languages
ServerName admin.oldking.org
ErrorLoglogs
/oldking
.admin-error_log
CustomLoglogs
/oldking
.admin-access_log common
<Directory
"/www/ phpMyAdmin-4.6.5.2-all-languages"
>
#这两行必须开,否则http协议的数据转发到https协议就实现不了
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
<
/Directory
>
<
/VirtualHost
>
eof
|
7 https配置
1
2
3
4
5
6
7
8
9
10
|
vim
/etc/httpd/conf
.d
/ssl
.conf
DocumentRoot
"/www/ phpMyAdmin-4.6.5.2-all-languages"
ServerName admin.oldking.org
SSLCertificateFile
/etc/httpd/ssl/httpd
.crt
#授权证书
SSLCertificateKeyFile
/etc/httpd/ssl/httpd
.key
#http私钥
<Directory
"/www/ phpMyAdmin-4.6.5.2-all-languages"
>
Options None
AllowOverride None
Require all granted
<
/Directory
>
|
最后
把证书导到浏览器内,更改主机hosts文件加以下两行
bbs.oldking.org 172.16.29.2
admin.oldking.org 172.16.29.2
总结
配置步骤无非是环境和文件的准备,数据库和证书的,配置网页需要环境,最后配置httpd,https也无非是一个比较特殊的httpd的虚拟主机。配置的重点也是当下主要网站都使用的手段在于,文件压缩传输和把HTTP协议的数据转发到https上。
附件:http://down.51cto.com/data/2368501
本文转自Ailu0li 51CTO博客,原文链接:http://blog.51cto.com/oldking/1884050,如需转载请自行联系原作者