Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 1.32 KB

README.md

File metadata and controls

46 lines (36 loc) · 1.32 KB

PHP 反向代理

基于 https://github.com/jshensh/php-curl-class 的一个应用

需要修改的配置文件

nginx.conf

请替换 Line 5 的域名以及 Line 7 的实际路径

index.php

请替换 Line 6 的源站访问协议、Line 7 的源站域名以及 Line 8 的当前站点域名,Line 154 起的输出内容替换数组视情况修改

功能

  • 转发用户的 GET 请求
  • 转发用户的 POST 请求
  • 转发用户的 PUT 请求
  • 转发用户的 DELETE 请求
  • 转发用户发送的所有 Header(除 Accept-Encoding 和 Host)
  • 转发服务器返回的所有 Header(除 Content-Length 和 Content-Encoding)
  • 替换服务器返回的内容

搭建反代(基于 lnmp)

#!/bin/sh

originProtocol="http"
originSite="baidu.com"
thisSite="example.com"
# 以上三行需要修改
cd /home/wwwroot
git clone https://github.com/jshensh/phpReverseProxy ${thisSite}
rm -rf ${thisSite}/.git/
cd ${thisSite}
sed -i "s/example.com/${thisSite}/g" ./nginx.conf
mv ./nginx.conf /usr/local/nginx/conf/vhost/${thisSite}.conf
sed -i "s/http/${originProtocol}/g" ./index.php
sed -i "s/example.com/${thisSite}/g" ./index.php
sed -i "s/baidu.com/${originSite}/g" ./index.php
composer install
chown -R www:www ./*
lnmp nginx reload