1.Nginx充当中介,将请求转发给其他LAMP
192.168.200.112中yum安装LAMP
[root@localhost ~]# yum -y install httpd mairadb mariadb-server php php-mysql
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl start mariadb
[root@localhost ~]# vim /var/www/html/test.php //添加测试文档
192.168.200.111中安装nginx
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf //修改主配置文件,添加location
location ~* .php$ {
proxy_pass http://192.168.200.112;
}
[root@localhost ~]# 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@localhost ~]# killall -HUP nginx // 重启
在网页中测试
111/112中测试结果相同,转发成功
2.Nginx通过FPM模块,调用PHP环境
[root@nginxetc]# vim /usr/local/nginx/conf/nginx.conf //修改主配置文件,添加location
server {
…… //省略部分信息
location / {
root html;
index index.php index.html index.htm;
}
location ~ .php$ { //访问php页面的配置段
root html; //PHP网页文档根目录
fastcgi_pass 127.0.0.1:9000; //php-fpm的监听地址
fastcgi_indexindex.php; //PHP首页文件
include fastcgi.conf; //包括fastcgi.conf样本配置
}
}
[root@nginx~]# cat /usr/local/nginx/html/php.php //创建测试文档
<?php
phpinfo();
?>
测试成功