简单的:vue内网穿透配置

什么是内网穿透:

一般来说我们在本地运行项目,都是通过

http://localhost:8082/ 

http://10.0.10.27:8082/

复制代码

这样来访问本地运行的项目,不知道大家有没有遇到过这样访问本地项目的

http://dev.xxxxxxxx.cn:8080/618

复制代码

通过一个域名地址来访问本地项目;

为什么要这样访问呢?

  • 提供内网穿透服务

  • 连接内网服务器,在外网演示内网web站点

  • 无需服务器部署,快速调试本地程序,方便快速开发微信公众号和微信小程序

  • 支持http、https协议站点,省去证书中间件复杂配置,http协议站点直接升级为https站点

  • 支持TCP,UDP协议端口转发。支持数据库、SSH、远程桌面、网络摄像头等等开放到外网。

简单实现:

怎么实现呢?(vue为例)

第一步,修改vue的配置 disableHostCheck

disableHostCheck是webpack中webpack-dev-server的一个配置项;
感兴趣大家可以自己去看一下;

vue-cli版本3.0的情况下修改vue.config.js的配置

module.exports = {
  devServer: {
    disableHostCheck: true
  }
}

复制代码

这一步是让vue 本地服务 能被外部IP访问;

接着就是修改本地电脑的 host配置:

一般来说window的host文件路径为:

C:\WINDOWS\system32\drivers\etc

host文件内容:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost

复制代码

添加我们的域名地址:

    增加这一句
    
       127.0.0.1  你的域名
复制代码

最后:

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
#      102.54.94.97     rhino.acme.com          # source server
#       38.25.63.10     x.acme.com              # x client host

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost


       127.0.0.1     dev.xxxxxxx.cn

复制代码

最后大功告成:

我们就可以 这样dev.xxxxxxxx.cn:8080/618 访问本地的项目了;

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享