基于nginx-php反向代理配置

mac2024-06-03  31

系统环境: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 安装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解析 测试访问

最新回复(0)