[root@lb01 ~]# vim /etc/nginx/conf.d/linux.lb.com.conf
upstream web_group {
server 172.16.1.7;
server 172.16.1.8;}
server {
listen 80;
server_name linux.lb.com;
location / {
proxy_pass http://web_group;
include proxy_params;}}
[root@lb01 ~]# vim /etc/nginx/conf.d/linux.wp.com.conf
upstream blog {
server 172.16.1.7;
server 172.16.1.8;}
server {
listen 80;
server_name linux.wp.com;
location / {
proxy_pass http://blog;
include proxy_params;}}#重启[root@lb01 ~]# systemctl restart nginx
2.配置hosts查看网站
10.0.0.4 linux.wp.com
3.配置zh的负载均衡
[root@lb01 ~]# vim /etc/nginx/conf.d/linux.zh.com.conf
upstream zh {
server 172.16.1.7;
server 172.16.1.8;}
server {
listen 80;
server_name linux.zh.com;
location / {
proxy_pass http://zh;
include proxy_params;}}
[root@web01 code]# cp /code/php/{config.sample.inc.php,config.inc.php}[root@web01 code]# vim /code/php/config.inc.php$cfg['Servers'][$i]['host']='172.16.1.51';
4)授权站点目录
[root@web01 code]# chown -R www.www /code/
5)配置nginx
[root@web01 ~]# vim /etc/nginx/conf.d/linux.php.com.conf
server {
listen 80;
server_name linux.php.com;
root /code/php;
location / {
index index.php;}
location ~* \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;}}[root@web01 ~]# systemctl restart nginx
6)配置hosts访问
#配置hosts
10.0.0.7 linux.php.com
#访问页面 http://linux.php.com/#报错:
Error during session start; please check your PHP and/or webserver log file and configure your PHP installation properly. Also ensure that cookies are enabled in your browser.
session_start(): open(SESSION_FILE, O_RDWR) failed: Permission denied (13)
session_start(): Failed to read session data: files (path: /var/lib/php/session)#解决:[root@web01 ~]# chown -R www.www /var/lib/php/session
7)再次登录测试
#登录测试,如果登录用户密码错误
mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'172.16.1.7'(using password: YES)#数据库授权
MariaDB [(none)]> grant all on *.* to root@'172.16.1.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
[root@lb01 ~]# vim /etc/nginx/conf.d/linux.php.com.conf
upstream phpmyadmin {
server 172.16.1.7;
server 172.16.1.8;}
server {
listen 80;
server_name linux.php.com;
location / {
proxy_pass http://phpmyadmin;
include proxy_params;}}[root@lb01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@lb01 ~]# systemctl restart nginx
2)访问
#配置hosts
10.0.0.4 linux.php.com
#访问报错
Failed to set session cookie. Maybe you are using HTTP instead of HTTPS to access phpMyAdmin.
6.解放决方式一:挂载session文件的目录
[root@web01 ~]# mount -t nfs 172.16.1.31:/data/wp /var/lib/php/session/[root@web02 ~]# mount -t nfs 172.16.1.31:/data/wp /var/lib/php/session/
7.解决方式二:使用redis实现session共享
1)安装redis
[root@db01 ~]# yum install -y redis
2)配置服务
[root@db01 ~]# vim /etc/redis.conf
bind 172.16.1.51