nginx反向代理LAMP解析PHP环境
nginx反向代理LAMP解析php环境
1、nginx充当中介,将请求转发给其他LAMP
2、nginx通过FPM模块,调用php环境
===================================
两台主机 ,一台主机nginx 一台主机为LAMP
构建LAMP
killall -9 nginx
yum -y install httpd mariadb mariadb-server php php-mysql
systemctl start httpd
systemctl start mariadb
--------------------------------
vim /var/www/html/test.php
<?php
phpinfo();
?>
保存退出
浏览器访问IP/test.php
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~·
1、nginx充当中介,将请求转发给其他LAMP
vim /usr/local/nginx/conf/nginx.conf
location ~* \.php$ {
proxy_pass http://192.168.200.67; //LAMP 的IP
}
nginx -t
killall -HUP nginx
浏览器测试:192.168.200.66/test.php
在LAMP上传论坛的软件包,并完成安装 然后再浏览器中进行访问
192.168.200.66/bbs
----------------------------------------------------------------
第一台机器:nginx安装
[root@nginx ~]# systemctl stop firewalld
[root@nginx ~]# setenforce 0
[root@nginx ~]# iptables -F
[root@nginx ~]# yum -y install pcre-devel zlib-devel openssl-devel gcc gcc-c++ make
[root@nginx ~]# useradd -M -s /sbin/nologin nginx
[root@nginx ~]# ls
anaconda-ks.cfg 公共 图片 音乐
initial-setup-ks.cfg 模板 文档 桌面
nginx-1.16.1.tar.gz 视频 下载
[root@nginx ~]# tar xf nginx-1.16.1.tar.gz -C /usr/src/
[root@nginx ~]# cd /usr/src/nginx-1.16.1/
[root@nginx nginx-1.16.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module && make && make install
[root@nginx nginx-1.16.1]# ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/
[root@nginx nginx-1.16.1]# ll /usr/local/bin/nginx
lrwxrwxrwx. 1 root root 27 11月 21 08:58 /usr/local/bin/nginx -> /usr/local/nginx/sbin/nginx
[root@nginx nginx-1.16.1]# nginx
浏览器中访问192.168.200.66
-------------------------------------------------------------------------
第二台LAMP
[root@LAMP ~]# iptables -F
[root@LAMP ~]# setenforce 0
[root@LAMP ~]# systemctl stop firewalld
[root@LAMP ~]# yum -y install httpd mariadb mariadb-server php php-mysql
[root@LAMP ~]# systemctl start httpd
[root@LAMP ~]# systemctl start mariadb //搭建LAMP
·······················
[root@LAMP ~]# vim /var/www/html/test.php
<?php
phpinfo();
?>
再浏览器中进行访问192.168.200.67/test.php
---------------------------------
在第一台主机中修改
[root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf
location ~* \.php$ {
proxy_pass http://192.168.200.67;
}
//在server中添加
保存退出
[root@nginx ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@nginx ~]# killall -HUP nginx
在浏览器中192.168.200.66/test.php
----------------------------------------------------------------------------------------------
bbs论坛反向代理
==========
在第二台主机LAMP中上传bbs软件包ComsenzDiscuz-DiscuzX-master.zip
[root@LAMP ~]# unzip ComsenzDiscuz-DiscuzX-master.zip
[root@LAMP ~]# cd DiscuzX/
[root@LAMP DiscuzX]# mv upload/ /var/www/html/bbs
浏览器访问http://192.168.200.67/bbs
[root@LAMP DiscuzX]# cd /var/www/html/bbs/config/
[root@LAMP config]# ls
config_global_default.php index.htm
config_ucenter_default.php
[root@LAMP config]# cp config_global_default.php config_global.php
[root@LAMP config]# cp config_ucenter_default.php config_ucenter.php
[root@LAMP config]# cd ..
[root@LAMP bbs]# chmod -R 777 config/ data/ uc_client/ uc_server/
[root@LAMP config]# cd ..
[root@LAMP bbs]# chmod -R 777 config/ data/ uc_client/ uc_server/
[root@LAMP bbs]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database bbs;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on bbs.* to 'bbs'@'localhost' identified by '123456'; //设置用户权限
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> plush privileges;
MariaDB [(none)]>exit
Byby
在浏览器中192.168.200.66/index.php
完成!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!