首页 文章

通过LAN网络从另一台计算机访问localhost(xampp) - 如何?

提问于
浏览
114

我刚在家里 Build 了一个Wi-Fi网络 . 我的所有文件都在我的桌面计算机上(192.168.1.56),并希望从另一台计算机(192.168.1.2)访问那里的localhost .

在我的桌面上,我可以通过正常的http://localhost访问localhost . Apache像往常一样在端口80上运行 .

究竟我该怎么做才能实现这个目标?网上有文档,但它们要么不起作用,要么过于片段化,难以理解 .

我想我必须更改我的apache的httpd.conf文件和hosts文件 . 关于做出哪些改变的任何想法?

19 回答

  • -1

    所以我试图解决类似的问题,连接到我自己的局域网上一个完全不同的服务器,这样当电源中断然后恢复,我的服务器恢复在线,其他系统仍然可以与自动化连接 . 但是,我的问题是DHCP偶尔为我的服务器提供差异IP . 这个线程用NAMESERVER解决了我的问题,Windows本身就有这个问题 . 我直接连接到我的服务器IP通过批处理文件添加http://192.168.1.5来初始化连接但是当电源问题发生时它将无法连接 . 我将.bat文件更改为指向http://DESKTOP-actualnamewhereserver:port并完成 . 问题解决了 . 如果我没有't change my computers names then when DHCP hands DESKTOP-actualnamewhereserver a new IP address it will still identify as its own name on the LAN and therefore be able to accept the connection regardless of it'的IP地址 . 只需向无线局域网上的其他人提供托管Apache服务器的PC的名称,并告诉它名称为DESKTOP-DOUGHFACTORYHUT,他们将输入http://DOUGHFACTORYHUT:80或您的apache配置设置为托管的任何端口号,如LOCALHOST:80,这基本上是与您为服务器设置的DHCP或STATIC IP分配的本地动态IP地址相同的内容 .

  • 2

    Localhost只是环回的名称,例如它将自己称为“我” .

    要从其他计算机上查看它,你可能只需要http://192.168.1.56http://myPcsName如果它不起作用,你的计算机上可能有防火墙运行,或者httpd.conf只在127.0.0.1上监听

  • 0

    感谢您的详细解释 .

    只是为了精心设计,在Windows中,转到控制面板 - >防火墙,例外"add http and port 80" . 然后在服务中选中标记"http (web server port 80)"和"https (web server port 443)" ONLY ,如果您还需要https工作 . 好的,好的,关闭

    然后转到网络上的任何计算机并在Web浏览器中键入http://computer-name(您在其中更改防火墙并运行xampp)并且快乐的日子:)

  • 0

    当您希望将PHP应用程序安装在LAN服务器(而不是Web上)时,这些步骤可以遵循

    • 获取服务器的内部IP或静态IP(例如:192.168.1.193)

    • 在记事本中打开XAMPP> apache> conf> httpd.conf文件

    • 搜索听80

    • 上面的行就像 - #Listen 0.0.0.0:80 / 12.34.56.78:80

    • 更改IP地址并将其替换为静态IP

    • 保存httpd.conf文件,确保服务器指向#Listen 192.168.1.193:80

    • 在应用程序根目录config.php(db connection)中将localhost替换为服务器的IP地址

    注意:如果安装了防火墙,请确保将http端口80和8080添加到例外并允许侦听 . 转到控制面板> Windows防火墙>允许程序通过Windows防火墙进行通信>添加另一个程序名称:http端口:80再添加一个作为http - 8080

    如果IIS(Microsoft .Net Application Internet Information Server)与服务器上已有的任何Microsoft .Net应用程序一起安装,那么它将占用80端口 . 在这种情况下,将#Listen 192.168.1.193:80更改为#Listen 192.168.1.193:8080

    希望这可以帮助! :)

  • 0

    这很容易

    • 转到XAMPP控制面板

    • 点击apache> config> Apache(httpd.conf)
      enter image description here

    • 搜索 Listen 80 并替换为 Listen 8080

    • 之后使用 ipconfig 命令(cmd控制台)检查本地IP

    • 搜索 ServerName localhost:80 并替换为 your local ip:8080 (ex.192.168.1.156:8080)

    • 之后打开apache> config> Apache(httpd-xampp.conf)
      enter image description here

    • 搜索Alias / phpmyadmin "C:/xampp/phpMyAdmin/" AllowOverride AuthConfig Require local 替换为 Require all granted ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var

    • 转到xampp> config>单击服务和端口设置并更改apache端口 8080

    • 重启xampp

    • 然后从其他计算机上击中你的ip:8080(ex.192.168.1.156:8080)

  • 3

    这应该是基本设置所需的全部内容

    这种配置不会破坏localhost上的phpMyAdmin

    建议在运行服务器的设备上使用静态IP

    此示例使用192.168.1.x IP . 您的网络配置可能使用不同的IP

    在Apache的httpd.conf中你应该有:

    # Listen: Allows you to bind Apache to specific IP addresses and/or
    # ports, instead of the default. See also the <VirtualHost>
    # directive.
    #
    # Change this to Listen on specific IP addresses as shown below to 
    # prevent Apache from glomming onto all bound IP addresses.
    #
    #Listen 12.34.56.78:80
    Listen 80
    

    我会留空这个名字,所以它得到默认值:

    # ServerName gives the name and port that the server uses to identify itself.
    # This can often be determined automatically, but we recommend you specify
    # it explicitly to prevent problems during startup.
    #
    # If your host doesn't have a registered DNS name, enter its IP address here.
    #
    

    允许客人机器和你自己 . 作为安全注意事项,您可以避免允许来自所有人,而是使用特定的来宾IP,例如允许来自192.168.1.xxx,其中xxx是来宾计算机IP . 在这种情况下,您可能还需要考虑来宾计算机上的静态IP

    # Controls who can get stuff from this server.
    #
    #    Require all granted
    #   onlineoffline tag - don't remove
         Order Deny,Allow
    #     Deny from all
         Allow from all 
         Allow from 127.0.0.1
         Allow from ::1
         Allow from localhost
         Allow from 192.168.1.*YOURguestIP*
         Allow from 192.168.1.*YOURselfIP*
    </Directory>
    

    从托盘图标重新启动所有服务并置于联机状态

  • 16

    有时您的防火墙可能是问题 . 确保您已禁用防病毒防火墙监控 . 它对我有用 .

  • 5

    如果您正在使用XAMPP 1.8.3导航到文件httpd-xampp.conf并搜索“## New XAMPP安全概念#server-status | server-info”)“>

    Require local
         ErrorDocument 403 /error/XAMPP_FORBIDDEN.html.var
         </LocationMatch>
    

    剪切此代码并将其保存在某处以供以后使用,即恢复此功能(请记住删除此代码会使您的计算机容易受到攻击) . 在httpd-xampp.conf上保存更改,在XAMPP上重启服务,就是这样 .

  • 6

    转到任务栏中的xampp-control

    xampp-control -> Apache --> Config --> httpd.conf
    

    记事本将打开配置文件

    搜索

    听80

    在它上面的一行,会有这样的东西:12.34.56:80

    更改

    12.34.56:80 --> <your_ip_address eg:192.168.1.5>:80
    

    重启apache服务并检查它,希望它应该工作...

  • 4

    如果您连接到Wi-Fi网络,则更简单 . 找到你拥有的IP连接到Wi-Fi . 例如:

    你的IP是“10.10.55.67” .

    然后在您的计算机中启动xampp服务器 .

    然后在连接到相同Wi-Fi n / w的任何其他计算机中,键入

    http://your-ip

    例如: http://10.10.55.67

  • 4

    这个工具为我节省了很多,因为我的机器上没有管理员权限,并且已经安装了nodejs . 由于某种原因,我的网络上的配置不允许我访问仅将IP指向浏览器的其他计算机 .

    # Using a local.dev vhost
    $ browser-sync start --proxy
    
    # Using a local.dev vhost with PORT
    $ browser-sync start --proxy local.dev:8001
    
    # Using a localhost address
    $ browser-sync start --proxy localhost:8001
    
    # Using a localhost address in a sub-dir
    $ browser-sync start --proxy localhost:8080/site1
    

    http://www.browsersync.io/docs/command-line/

  • 1

    确保您已按照本页其他答案中的说明设置了appache配置后,您可能还需要通过防火墙打开TCP端口,如下所述:

    https://superuser.com/questions/569227/xampp-is-not-accessible-from-other-computer-through-lan-when-firewall-is-enable

  • 13

    首先转到Windows机器的网络和共享中心 . 只需按照一些步骤获取您的IPv4地址 .
    Just See The Image Illustration

    Put the IPv4 adress on another computer browser. example,http//192.168.0.102

    Note

    • 打开Windows防火墙(如果不起作用,否则可选)
  • -2

    以下是我在 windows 10 上为我所做的工作:

    1)按 windows + r 并键入 cmd . 在命令提示符下键入 ipconfig
    2)找到你的 ipv4 地址并将你的网站网址重命名为该网址,例如:http://192.168.0.2/example .
    3)现在确保 firewall 可以访问 Apache HTTP Server . 搜索“ Allow an app through windows firewall ”窗口,然后单击右上角的 change settings 并确保Apache HTTP Server左侧有一个勾选,私有或公共上有一个勾选 . 希望能帮助到你

    现在,您可以从局域网中的其他PC访问该网站

  • 2

    首先,转到命令提示符并键入

    Notepad C:/windows/system32/drivers/etc/hosts

    然后在您的网站的网址下面添加您的IP地址 .

    其次,您转到命令提示符并键入 notepad c:/xampp/bin/apache/apache2.4.18/conf/extra/httpd-vhosts.conf

    然后在下面添加

    documentroot "Directory of your site"
    Allow from all
    Require all granted
    
  • 90
    <Files ".ht*">
     Require all denied
    </Files>
    
     replace to
    
    <Files ".ht*">
     Require local
    </Files>
    
  • 3

    Require Local 替换为 xampp\apache\conf\extra\httpd-xampp.conf 文件中的 Require all granted .

  • 0

    我遇到了这个问题 . 我在一台虚拟机中使用XAMPP,该网络设置为“NAT” . 我把它改成了“Bridged”,问题解决了 .

  • 39

    我完全同意BugFinder .

    简单来说,只需将ip地址192.168.1.56放在192.168.1.2上运行的浏览器中!

    如果它不起作用,那么有以下可能的原因:

    • 网络连接问题:

    • 首先在192.168.1.2计算机上的命令提示符/终端中使用ping 192.168.1.56命令检查网络连接 .

    • 防火墙问题:您的Windows防火墙设置没有XAMPP(apache)的允许规则 . (最可能的问题)

    • (解决方案)转到高级防火墙设置并添加Apache可执行文件的入站和出站规则 .

    • Apache配置问题 . :您的apache配置为仅侦听本地请求 .

    • (解决方案)你可以打开httpd.conf文件并将Listen 127.0.0.1:80替换为Listen 80或* Listen:80

    • 与其他服务器的端口冲突(IIS等)

    • (解决方案)关闭apache服务器,然后在浏览器中打开本地主机 . 如果获得任何响应,则关闭该服务器然后启动Apache .

    如果上述所有方法都不起作用,那么你的apache server.try上可能存在一些配置问题,无法重新安装它并将所有php文件(htdocs)传输到新安装的XAMPP / WAMP .

相关问题