web实验(2)
实验1
-
搭建nginx+ssl的加密认证web服务器
-
第一步:准备工作
# 恢复快照
[root@server ~]# setenforce 0[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# yum install nginx mod_ssl -y
[root@server ~]# systemctl start nginx # 启动
[root@server ~]# systemctl enable nginx # 设置开机启动
第二步:新建存储网站数据文件的目录
[root@server ~]# mkdir -p /www/zy
# 私用xftp将windows的zy网站数据文件上传到/www/zy目录中
第三步:制作证书
# 在/etc/nginx目录下制作整数所用的私钥文件zy.key
[root@server ~]# openssl genrsa -aes128 2048 > /etc/nginx/zy.key
Generating RSA private key, 2048 bit long modulus (2 primes)
............+++++
......................................................................................................................................................................................................+++++
e is 65537 (0x010001)
Enter pass phrase: # 输入加密私钥的密码123456
Verifying - Enter pass phrase: # 再输一遍# 制作证书
[root@server ~]# openssl req -utf8 -new -key /etc/nginx/zy.key -x509 -days 365 -out /etc/nginx/zy.crt
Enter pass phrase for /etc/nginx/zy.key: # 需要输入加密私钥的密码
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
# 注意:下列证书信息项目,在面试时常问
Country Name (2 letter code) [AU]:86 # 国家代码
State or Province Name (full name) [Some-State]:shanxi # 省份
Locality Name (eg, city) []:xi'an # 城市
Organization Name (eg, company) [Internet Widgits Pty Ltd]:openlab# 公司
Organizational Unit Name (eg, section) []:RHCE # 部门
Common Name (e.g. server FQDN or YOUR name) []:server # 主机名
Email Address []:andy@qq.com # 邮箱# 在加载SSL支持的Nginx并使用上述私钥时除去必须的口令
[root@server ~]# cd /etc/nginx
[root@server nginx]# cp zy.key zy.key.org
[root@server nginx]# openssl rsa -in zy.key.org -out zy.key
Enter pass phrase for zy.key.org: # 输入加密私钥的密码
writing RSA key
第五步:修改配置文件
[[root@server nginx]# cd ~
[root@server ~]# vim /etc/nginx/nginx.confserver {
listen 443 ssl http2;
server_name 192.168.48.130;
root /www/zy;
ssl_certificate /etc/nginx/zy.crt;
ssl_certificate_key /etc/nginx/zy.key;
}
server { # 输入http跳转到https
listen 80;
server_name 192.168.48.130;
return 301 https://192.168.48.130;
}
第六步:重启服务
[root@server nginx]# cd ~
[root@server ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@server nginx]# systemctl start nginx
第七步:测试
使用LNMP搭建私有云存储
准备工作
恢复快照,关闭安全软件
[root@server ~]# setenforce 0
[root@server ~]# systemctl stop firewalld
搭建LNMP环境
[root@server ~]# yum install nginx mariadb-server php* -y
上传软件
-
使用xftp将nextcloud-25.0.1.zip软件压缩包上传到Linux的根目录,并解压缩
[root@server ~]# cd /
[root@server /]# unzip /nextcloud-25.0.1.zip
设置nextcloud安装命令权限
[root@server /]# chmod -Rf 777 /nextcloud
设置数据库
[root@server /]# systemctl start mariadb # 启动数据库
[root@server /]# mysql
# 数据库设置
MariaDB [(none)]> create database nextcloud; # 创建数据库MariaDB [(none)]> create user 'nextcloud'@'localhost' identified by '123456'; # 创建用户及密码
MariaDB [(none)]> grant all on nextcloud.* to 'nextcloud'@'localhost';
# 设置权限
MariaDB [(none)]> exit # 退出
重启数据库
[root@server /]# systemctl restart mariadb
配置nginx
[root@server /]# vim /etc/nginx/nginx.conf
server {
listen 80;
server_name 192.168.48.130;
root /nextcloud;
}
重启nginx服务
[root@server /]# systemctl start nginx
安装
-
打开浏览器后输入服务器IP地址,进入nextcloud安装向导
-
管理员的用户名即密码自定
-
存储与数据库:选择MySQL/MariaDB,设置数据库用户为nextcloud,密码:123456,数据库名:nextcloud,主机名:localhost
内网穿透
cpolar的域名信任
[root@server ~]# vim /nextcloud/config/config.php
# 按照下面的内容对源文件进行修改
<?php
$CONFIG = array ('instanceid' => 'ocvy7jm0iqom','passwordsalt' => 'jLg0GXwJtlj8vowMsLpN5MbBSRsoiC','secret' => 'ayTVaC6dsHrSKgXazVP6llFMWdNVxjF582v5pAPKuyEecdTU','trusted_domains' =>array (0 => '192.168.48.130',1 => '2dc0afad.r17.cpolar.top', # 需添加),'datadirectory' => '/nextcloud/data','dbtype' => 'mysql','version' => '25.0.1.1','overwrite.cli.url' => 'http://192.168.48.130','dbname' => 'nextcloud','dbhost' => 'localhost','dbport' => '','dbtableprefix' => 'oc_','mysql.utf8mb4' => true,'dbuser' => 'nextcloud','dbpassword' => '123456','installed' => true,
);
# 保存退出后重试