ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[toc] 场景:微信开发只能在服务器上开发,不方便调试。反向代理后,可以在本地进行开发和调试。 >[info]软件下载的链接:http://download.csdn.net/download/qq\_33862644/10220524 ## :-: **设置流程** ### :-: **1、线上设置** ![](https://box.kancloud.cn/f0cb8310220f7584217f6e232472c0d3_573x418.png) ![](https://box.kancloud.cn/8b03673cd8151bd26a16c368302148a2_562x678.png) 然后输入几条命令: ``` shell ssh -L 0.0.0.0:80:127.0.0.1:80 root@127.0.0.1 ss -ntl 查看所有使用中的端口 ps aux 查看所有进程 ``` 编辑服务器上面的/etc/ssh/sshd_config 搜索gatewayports 将gatewayports 改为yes >[warning]这时你会发现输入:netstat -nltp指令。看见的80端口,后面不再是nginx了 ### :-: **2、本地设置** ![](https://box.kancloud.cn/c410883f5378098a58cd56ac5729b1b5_659x386.png) ~~~ #好评返现 server { listen 80 default_server; server_name test; root "D:/phpStudy/WWW/hpfx/public"; location / { index index.html index.htm index.php; autoindex on; # 伪静态配置 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; fastcgi_param TP_ENV sixian; } } ~~~ ### :-: **3、测试** 浏览器中输入127.0.0.1,然后修改本地代码 ![](https://box.kancloud.cn/bd25cb45728b136d9ff67b0db593225d_982x155.png) ## :-: **开启/关闭反向代理的步骤** - 使用本地(开启):打开Bitvise SSH Client软件。线上就可以直接访问本地了 >[warning]线上nginx要关闭,因为线上的80端口是给Bitvise SSH Client软件使用的(占用了80端口,替代了nginx) - 使用线上(关闭):关闭Bitvise SSH Client软件,开启线上的nginx ## :-: **原理** - 微信服务器把请求发给线上服务器。线上服务器把请求发到了你本地服务器(如 phpstudy的ngxin)。这样就可以直接用本地的项目和微信服务器交互。 - 只不过是把项目部署到了线上,真正访问的服务器是你本地服务器。 - vhost中的配置也是需要的,因为线上的nginx关闭后,项目需要一个服务器,这时候用的就是你本地服务器了