部署方法
假设本机的局域网ip为192.168.1.136(查询本机局域网ip的方法),部署方法如下:
1.在phpstudy上配置上网站,设置好虚拟域名和端口号(不会的可以百度phpstudy的手册)
2.phpstudy修改配置
2.1.点击菜单栏“设置-配置文件-httpd.conf” 里面取消注释以下三行
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule rewrite_module modules/mod_rewrite.so
2.2.在设置-配置文件-vhosts.conf里面找到网站对应的配置文件(一般以网站名称命名),然后修改成如下配置,注意修改端口号与第1步设置的端口号一致
<VirtualHost *:第1步设置的端口号>
ServerName 第1步设置的虚拟域名
DocumentRoot 网站所在的文件夹,例如D:/web
DirectoryIndex index.html index.php
ErrorLog "错误日志文件,可以随便填一个文件"
CustomLog "网站日志文件,可以随便填一个文件" common
<Directory "网站所在的文件夹,例如D:/web">
Order allow,deny
Allow from all
AllowOverride All
Require all granted
DirectoryIndex index.php index.cgi index.html
</Directory>
<proxy *>
Order allow,deny
Allow from all
</proxy>
ProxyPass /你的反向代理关键词例如api 你的反向代理域名例如https://api.wangzhan.com
</VirtualHost>
修改后的文件示例:
<VirtualHost *:8000>
ServerName test.web.com
DocumentRoot D:/web/test
DirectoryIndex index.html index.php
ErrorLog "D:/log/webErr.log"
CustomLog "D:/log/web.log" common
<Directory "D:/web/test">
Order allow,deny
Allow from all
AllowOverride All
Require all granted
DirectoryIndex index.php index.cgi index.html
</Directory>
<proxy *>
Order allow,deny
Allow from all
</proxy>
ProxyPass /api https://api.wangzhan.com
</VirtualHost>
3.开启局域网IP访问
在phpstudy菜单栏上点击“设置-配置文件-hosts”,修改第1步设置的域名配置,将127.0.0.1 改为本机的局域网ip,例如
修改之前可能为:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 web.test.com
修改之后为:
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
192.168.1.136 web.test.com
4.在网站根目录新增一个文件名为:.htaccess,文件内容如下
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#RewriteRule ^index\.html$ [L]
RewriteRule ./index.html [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
</IfModule>
5.重启apache后,即可在局域网其他计算机的浏览器输入域名:端口号(即http://192.168.1.136:8000)进行访问