基于nginx-php反向代理配置

系统环境:centos7 X3

安装nginx

方法一:

	rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum info nginx
 yum install nginx

方法二:

1.更换源

	mv /etc/yum.repos.d/CentOs-Base.repo /etc/yum.repos.d/CentOs-Base.repo_bak
	cd  /etc/yum.repos.d/
	wget  http://mirrors.aliyun.com/repo/Centos-7.repo
	mv Centos-7.repo CentOs-Base.repo
	yum clean all && yum makecache && yum update
		正式安装:
	//一键安装上面四个依赖
	yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel

2.下载并解压

//创建一个文件夹
cd /usr/local
mkdir nginx
cd nginx
//下载tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz(版本自定义)
tar -xvf nginx-1.13.7.tar.g
  1. 安装nginx
//进入nginx目录
cd /usr/local/nginx
//执行命令
./configure
//执行make命令
make
//执行make install命令
make install

前面俩台分别下载apache,且其中一台安装php,php-fpm。

yum install httpd php php-fpm

这俩台web服务器分别配置主页文件,和更改监听地址,重启服务。

web1 172.19.80.11
echo test1 > /var/www/html/index.html
-------------------------------------
cat  /var/www/html/index.php
<?php
	phpinfo();
?>
-------------------------------------
vim /etc/httpd/conf/httpd.conf
Listen 80  ⇒ Listen 6111
添加index.php
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
保存退出
systemctl restart httpd php-fpm
systemctl stop firewalld
setenforce 0
ss -nplt | grep 6111
ss -nplt | grep 9000
测试访问 curl 172.19.80.11
web2 172.19.80.12
echo test2 > /var/www/html/index.html
vim /etc/httpd/conf/httpd.conf
Listen 80  ⇒ Listen 6112
systemctl restart httpd
systemctl stop firewalld
setenforce 0
保存退出
ss -nplt | grep 6112
测试访问 curl 172.19.80.12

nginx代理设置

---------------------------
	本地php测试
	server {
    		listen        80;
    		root /usr/share/nginx/html;
    		server_name 172.19.80.128;
        		location / {
        		index  index.html index.htm;
   			 }
----------------------------------
upstream mysvr(注:html) {
		server 172.19.80.12:6112
		}
upstream mysvrd(注:php) {
     	 server 172.19.80.11:6111;
		}	
server {
    		listen        80;
			#    root /tmp/nginx/html;
		    server_name www.qq12.com;
		    location / {
        	proxy_pass  http://mysvr;
        	index  index.html index.htm;
    	}
 location ~ \.php$ {
#        root           html;
#       try_files $uri =404;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        (防止出现FastCGI sent in stderr: "Primary script unknown"错误,文件找不到)
        include        fastcgi_params;
        proxy_pass  http://mysvrd;
    } 
最后:
    本地做个dns解析
    测试访问

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值