php WAMP 无法访问本地网络 403 Forbidden

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23382627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:41:06  来源:igfitidea点击:

WAMP Cannot access on local network 403 Forbidden

phpmysqlapachewampserver

提问by Ahmad Saleh

I know this question has been asked a lot of times

我知道这个问题已经被问过很多次了

I followed Most of the answers in the internet But I still get the same Message

我遵循了互联网上的大多数答案但我仍然收到相同的消息

403 Forbidden

You don't have permission to access / on this server.

403 禁地

您无权访问 / 在此服务器上。

It is weird that when I access using the same PC to localhost:1234it runs normally but if I access using my IP address 192.168.0.188:1234

奇怪的是,当我使用同一台 PC 访问它时,localhost:1234它运行正常,但如果我使用我的 IP 地址访问192.168.0.188:1234

Also which is really weird is that I tried to install WAMP on other PC and without any configuration I could access to that PC.

另外,非常奇怪的是,我尝试在其他 PC 上安装 WAMP,但没有任何配置就可以访问该 PC。

So I thought it's because McAfee and Firewall so I open port on Widows and McAfee and nothing changed also I turned off Firewall and still nothing change.

所以我认为这是因为 McAfee 和防火墙,所以我在 Widows 和 McAfee 上打开了端口,但没有任何变化,我也关闭了防火墙,但仍然没有任何变化。

Then for no reason I opened port through the Router “port forwarding” and still nothing changed.

然后我无缘无故地通过路由器“端口转发”打开了端口,但仍然没有任何变化。

I don't think that it's because my configuration in WAMP since I am still able to get this 403 ForbiddenMessage and also by using other PC without any configuration I could access it.

我不认为这是因为我在 WAMP 中的配置,因为我仍然能够获取此403 Forbidden消息,并且通过使用其他没有任何配置的 PC 我可以访问它。

Both PCs are setup like this:

两台电脑都是这样设置的:

Windows 8 Pro

视窗 8 专业版

  • WAMP Wampserver:2.4
  • Apache Version:2.4.4
  • PHP Version:5.4.12
  • MySQL Version:5.6.12
  • WAMP Wampserver:2.4
  • Apache 版本:2.4.4
  • PHP 版本:5.4.12
  • MySQL 版本:5.6.12

The accessible PC uses Microsoft Security Essentials.

可访问的 PC 使用Microsoft Security Essentials

The inaccessible PC uses McAfee Internet Security.

无法访问的 PC 使用McAfee Internet Security

I tried to turn off WAMPand start IISFor Microsoft Server (I works perfectly From any PC) but WAMP is still not not working

我试图关闭 WAMP启动 IISFor Microsoft Server(我在任何 PC 上都可以完美运行)但 WAMP 仍然无法正常工作

I followed these tutorial:

我遵循了这些教程:

And the Stack Overflow answers here:

堆栈溢出在这里回答:

回答by RiggsFolly

If you are using WAMPServer 3 See bottom of answer

如果您使用的是 WAMPServer 3 请参阅答案底部

For WAMPServer versions <= 2.5

对于 WAMPServer 版本 <= 2.5

By default Wampserver comes configured as securely as it can, so Apache is set to only allow access from the machine running wamp. Afterall it is supposed to be a developmentserver and nota live server.

默认情况下,Wampserver 的配置尽可能安全,因此 Apache 设置为仅允许从运行 wamp 的机器访问。毕竟它应该是一个开发服务器而不是一个实时服务器。

Also there was a little error released with WAMPServer 2.4 where it used the old Apache 2.2 syntax instead of the new Apache 2.4 syntax for access rights.

此外,WAMPServer 2.4 发布了一个小错误,它使用旧的 Apache 2.2 语法而不是新的 Apache 2.4 语法来获取访问权限。

You need to change the security setting on Apache to allow access from anywhere else, so edit your httpd.conffile.

您需要更改 Apache 上的安全设置以允许从其他任何地方访问,因此请编辑您的httpd.conf文件。

Change this section from :

将此部分更改为:

#   onlineoffline tag - don't remove
     Order Deny,Allow
     Deny from all
     Allow from 127.0.0.1
     Allow from ::1
     Allow from localhost

To :

到 :

#   onlineoffline tag - don't remove
    Require local
    Require ip 192.168.0

The Require localallows access from these ip's 127.0.0.1 & localhost & ::1.

Require local允许来自这些IP的访问127.0.0.1 & localhost & ::1

The statement Require ip 192.168.0will allow you to access the Apache server from any ip on your internal network. Also it will allow access using the server mechines actual ip address from the server machine, as you are trying to do.

该语句Require ip 192.168.0将允许您从内部网络上的任何 IP 访问 Apache 服务器。它还允许使用服务器机器上的服务器机器的实际 IP 地址进行访问,正如您所尝试的那样。

WAMPServer 3 has a different method

WAMPServer 3 有不同的方法

In version 3 and > of WAMPServer there is a Virtual Hosts pre defined for localhostso you have to make the access privilage amendements in the Virtual Host definition config file

在 WAMPServer 的版本 3 和 > 中,预定义了一个虚拟主机,localhost因此您必须在虚拟主机定义配置文件中修改访问权限

First dont amend the httpd.conffile at all, leave it as you found it.

首先httpd.conf根本不要修改文件,保留原样。

Using the menus, edit the httpd-vhosts.conffile.

使用菜单编辑httpd-vhosts.conf文件。

enter image description here

在此处输入图片说明

It should look like this :

它应该是这样的:

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot D:/wamp/www
    <Directory  "D:/wamp/www/">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

Amend it to

修改为

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot D:/wamp/www
    <Directory  "D:/wamp/www/">
        Options +Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Hopefully you will have created a Virtual Host for your project and not be using the wamp\wwwfolder for your site. In that case leave the localhost definition alone and make the change only to your Virtual Host.

希望您已经为您的项目创建了一个虚拟主机,而不是wamp\www为您的站点使用该文件夹。在这种情况下,不要管本地主机定义,只对您的虚拟主机进行更改。

Dont forget to restart Apache after making this change

进行此更改后不要忘记重新启动Apache

回答by Michel

For Apache 2.4.9

对于 Apache 2.4.9

in addition, look at the httpd-vhosts.conffile in C:\wamp\bin\apache\apache2.4.9\conf\extra

另外看看C:\wamp\bin\apache\apache2.4.9\conf\extra中的httpd-vhosts.conf文件

<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot C:/wamp/www
<Directory "C:/wamp/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require local
</Directory>
</VirtualHost>

Change to:

改成:

<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot C:/wamp/www
<Directory "C:/wamp/www/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Require all granted
</Directory>
</VirtualHost>

changing from "Require local" to "Require all granted" solved the error 403 in my local network

从“要求本地”更改为“要求所有授予”解决了本地网络中的错误 403

回答by Mayuri

I got this answer from here. and its works for me

我从这里得到了这个答案。它对我有用

Require local

Change to

改成

Require all granted
Order Deny,Allow
Allow from all

回答by JakeGould

To expand on RiggsFolly's answer—or for anyone who is facing the same issue but is using Apache 2.2 or below—this format should work well:

为了扩展RiggsFolly的答案——或者对于任何面临同样问题但使用 Apache 2.2 或更低版本的人——这种格式应该可以很好地工作:

Order Deny,Allow
Deny from all
Allow from 127.0.0.1 ::1
Allow from localhost
Allow from 192.168
Allow from 10
Satisfy Any

For more details on the format changes for Apache 2.4, the official Upgrading to 2.2 from 2.4page is pretty clear & concise. Key point being:

有关 Apache 2.4 格式更改的更多详细信息,官方从 2.4 升级到 2.2页面非常清晰简洁。关键是:

The old access control idioms should be replaced by the new authentication mechanisms, although for compatibility with old configurations, the new module mod_access_compatis provided.

旧的访问控制习惯用法应该由新的身份验证机制替换,尽管为了与旧配置兼容,mod_access_compat提供了新模块。

Which means, system admins around the world don't necessarily have to panic about changing Apache 2.2 configs to be 2.4 compliant just yet.

这意味着,世界各地的系统管理员不必担心将 Apache 2.2 配置更改为 2.4 兼容。

回答by Jonathan LeRoux

For those who may be running WAMP 3.1.4 with Apache 2.4.35 on Windows 10 (64-bit)

对于那些可能在 Windows 10(64 位)上运行 WAMP 3.1.4 和 Apache 2.4.35 的人

If you're having issues with external devices connecting to your localhost, and receiving a 403 Forbidden error, it may be an issue with your httpd.confand the httpd-vhosts.conffiles and the "Require local" line they both have within them.

如果您的外部设备连接到本地主机时遇到问题,并收到 403 Forbidden 错误,则可能是您的httpd.confhttpd-vhosts.conf文件以及它们都包含的“要求本地”行存在问题他们。

[Before] httpd-vhosts.conf

[之前] httpd-vhosts.conf

<VirtualHost *:80>
 ServerName localhost
 ServerAlias localhost
 DocumentRoot "${INSTALL_DIR}/www"
 <Directory "${INSTALL_DIR}/www/">
   Options +Indexes +Includes +FollowSymLinks +MultiViews
   AllowOverride All
   Require local     <--- This is the offending line.
 </Directory>
</VirtualHost>

[After] httpd-vhosts.conf

[之后] httpd-vhosts.conf

<VirtualHost *:80>
 ServerName localhost
 ServerAlias localhost
 DocumentRoot "${INSTALL_DIR}/www"
 <Directory "${INSTALL_DIR}/www/">
   Options +Indexes +Includes +FollowSymLinks +MultiViews
   AllowOverride All
 </Directory>
</VirtualHost>

Additionally, you'll need to update your httpd.conffile as follows:

此外,您需要按如下方式更新httpd.conf文件:

[Before] httpd.conf

[之前] httpd.conf

DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
#   onlineoffline tag - don't remove

    Require local  #<--- This is the offending line.
</Directory>

[After] httpd.conf

[之后] httpd.conf

DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
#   onlineoffline tag - don't remove

#   Require local
</Directory>

Make sure to restart your WAMP server via (System tray at bottom-right of screen --> left-click WAMP icon --> "Restart all Services").

确保通过(屏幕右下角的系统托盘 --> 左键单击 WAMP 图标 -->“重新启动所有服务”)重新启动 WAMP 服务器。

Then refresh your machine's browser on localhost to ensure you've still got proper connectivity there, and then refresh your other external devices that you were previously attempting to connect.

然后在 localhost 上刷新您机器的浏览器以确保您在那里仍然有正确的连接,然后刷新您之前尝试连接的其他外部设备。

Disclaimer:If you're in a corporate setting, this is untested from a security perspective; please ensure you're keenly aware of your local development environment's access protocols before implementing any sweeping changes.

免责声明:如果您在公司环境中,从安全角度来看,这是未经测试的;在实施任何彻底的更改之前,请确保您敏锐地了解本地开发环境的访问协议。