建设第二个网站,利用 LNMP 实现 实现phpMyAdmin并利用redis会话保持,用页面管理数据库
在100web1、200web2上创建网站数据存放目录
[root@ubunt ~]# mkdir /data/php2
进入官网 https://www.phpmyadmin.net/下载
[root@ubunt php2]# wget https://files.phpmyadmin.net/phpMyAdmin/5.2.0/phpMyAdmin-5.2.0-all-languages.zip
[root@ubunt php2]# unzip phpMyAdmin-5.2.0-all-languages.zip 解包
[root@ubunt php2]# ls
phpMyAdmin-5.2.0-all-languages phpMyAdmin-5.2.0-all-languages.zip
[root@ubunt php2]# mv phpMyAdmin-5.2.0-all-languages/* . 把目录内的文件移动到ph2目录
[root@ubunt php2]# rm -rf phpMyAdmin-5.2.0-all-languages/ 删除目录及安装包
[root@ubunt php2]# rm -rf phpMyAdmin-5.2.0-all-languages.zip
[root@ubunt ~]# chown -R www-data. /data/php2 修改权限
修改网站配置文件
[root@ubunt ~]# cat /apps/nginx/conf/conf.d/php.conf
server {
listen 80;
server_name www.meng.org;
root /data/php;
index index.php;
location ~ .php$|ping|php-status {
root /data/php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS on;
include fastcgi_params;
}
}
server { 此为第二个网站配置文件
listen 80;
server_name www.fanchao.org;
root /data/php2;
index index.php;
location ~ .php$|ping|php-status {
root /data/php2;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_param HTTPS on; (如果客户端到反向代理不用https,不用加)
include fastcgi_params;
}
}
nginx -s reload
在反向代理服务器101上面修改配置文件
upstream webservers {
server 10.0.0.100;
server 10.0.0.200;
}
server { 不用https协议
listen 80;
server_name www.fanchao.org;
index index.php;
location / {
proxy_pass http://webservers;
proxy_set_header Host $http_host;
}
}
server {
listen 80;
server_name www.meng.org;
root /data/nginx/html/pc;
access_log /apps/nginx/logs/www.meng.org_access.log main;
return 302 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name www.meng.org;
ssl_certificate /apps/nginx/conf/conf.d/ssl/m50.wangxiaochun.com.pem;
ssl_certificate_key /apps/nginx/conf/conf.d/ssl/m50.wangxiaochun.com.key;
ssl_session_timeout 10m;
location / {
proxy_pass http://webservers;
proxy_set_header Host $http_host;
}
}
nginx -s reload
DNS解析,10.0.0.101 www.fanchao.org,访问www.fanchao.com成功生成MySQL管理登录界面
在100web、200web上拷贝config.sample.inc.php改为config.inc.php
[root@ubunt ph2]# cp config.sample.inc.php config.inc.php
更改config.inc.php,指向要管理数据库的地址
$cfg['Servers'][$i]['host'] = '10.0.0.8'; 把localhost改为要管理的数据库地址
在后端MySQL10.0.0.8上创建管理账号
mysql> create user admin@'10.0.0.%' identified by '123456';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all on *.* to admin@'10.0.0.%';
Query OK, 0 rows affected (0.01 sec)
访问www.fanchao.org 输入账号密码 登陆进去,刷新,会自动退出,并出现Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin.
原因是没有会话保持,需要把session放到redis里面
php有一个放session的配置文件,在php里面指定session存放的路径 在100、200web上改
[root@ubuntu2004 php2]#vim /etc/php/7.4/fpm/pool.d/www.conf 最下面添加
php_value[session.save_handler] = redis
php_value[session.save_path] = "tcp://10.0.0.8:6379"
[root@ubuntu2004 ph2]#systemctl restart php7.4-fpm.service 重启服务
访问www.fanchao.org 输入账号密码 登陆进去,刷新会看到ip在100、200之间变化
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
相关推荐: USACO section 2.1 The Castle(dfs)
The Castle IOI’94 – Day 1 In a stroke of luck almost beyond imagination, Farmer John was sent a ticket to the Irish Sweepstakes (r…