1.lnmp实现多个虚拟主机,分别部署wordpress和phpmyadmin应用,并设置phpmyadmin仅能通过https协议访问;

a.实现wordpress部署

一:部署wordpress

    1)安装,nginx,php-fpm,mysql-server,php-mysql

    2)启动nginx。php-fpm,mariadb服务

    3)配置nginx的主配置文件

LNMP_第1张图片

在http上下文里面写入一条include /nginx/vhost/*.conf;可以让/nginx/vhost/所有.conf结尾的文件中,所有http上下文内的指令生效;

     4)在/nginx/vhost/创建一个配置文件;

    配置内容如下

server {
        listen 8000;监听8000端口
        server_name www.myadmin.com;服务名称
        location  ~ \.php$ {
        root /myweb/word;  资源映射路径
        index index.php;   默认的主页
        fastcgi_index index.php;  //php-fpm默认反向代理的资源文件名
        fastcgi_pass 127.0.0.1:9000; //将请求的资源通过指定套接字发送给反向代理服务器
        fastcgi_param SCRIPT_FILENAME /myweb/word/$fastcgi_script_name; //php使用SCRIPT_FILENAME脚本执行/myweb/word/下的相应文件
        include /etc/nginx/fastcgi_params;
}
}

    5)重新载入配置文件,并通过浏览器访问

        LNMP_第2张图片       6)使用mysql创建用户,数据库,并给予相应的权限

LNMP_第3张图片

    7)    登录后,进入如下配置页面,需要在wordpress目录下创建wp-config.php并将下面指定文字复制进去

LNMP_第4张图片

8)完成后,刷新,即可

LNMP_第5张图片

 二:使用https配置phpmyadmin

    1)同理,创建新的配置文件

server {
        listen 443 ssl;
        server_name www.word.com;
        ssl_certificate /nginx/ssl/nginx.crt;  //CA颁发的证书
        ssl_certificate_key /nginx/ssl/nginx.key;  //对应的私钥
        location / {
        root /myweb/myadmin;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /myweb/myadmin/$fastcgi_script_name;
        include /etc/nginx/fastcgi_params;
}
}

      2)此前,需要自行给nginx颁发证书

在一个指定目录创建一个私钥,比如为nginx.key
# (umask 066;openssl genrsa -out nginx.key 2048)
Generating RSA private key, 2048 bit long modulus
.........................+++
.....................................+++
e is 65537 (0x10001)
使用该私钥做证书申请(后缀应为.csr)比如:nginx.csr
# openssl req -new -key nginx.key -out nginx.csr -days 365
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) [XX]:
State or Province Name (full name) []:HEBEI
Locality Name (eg, city) [Default City]:QHD
注意:应该保证此证书的国家省份和市与CA颁发机构的一致

给nginx颁发证书,一般颁发需要在/etc/pki/CA目录下进行,所以
[root@bogon CA]# openssl ca -in nginx.csr -out certs/nginx.crt -days 365

颁发完成后,将颁发的证书复制到私钥所在目录

    3)创建相应的资源站点,重启服务,使用https登录

    LNMP_第6张图片

使用本地用户和密码登录

LNMP_第7张图片

结束

    2.配置即使客户端通过http协议访问phpmyadmin站点,最终也可以让用户使用https重新请求访问;

   1)需要我们做一个uri重定向

    我在端口号为80的server下配置

        location ~ \.php$ {
        root /myweb/myadmin;
        index index.php;
        rewrite ^/(.*\.php)$  //当我们访问以.php结尾的重定向uir到https://172.16.0.149/寻找相应的资源,你访问的什么$1就代表什么
        }
}

    2)保存退出,重载服务

    3)我们使用火狐浏览器的F12可以查看数据请求响应 的具体过程,可以看到,我们访问172.16.0.149:80的时候,他们进行临时的转发

    LNMP_第8张图片

    4)转发到了https://172.16.0.149/index.php下

LNMP_第9张图片

LNMP_第10张图片