使用phpstudy在windows系统部署vue打包后的项目,在局域网内通过IP:端口号的形式访问

部署方法

假设本机的局域网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)进行访问

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值