Wamp - 通过 IP 而不是本地主机访问项目
Wamp - access project via IP instead of localhost
我尝试制作我的项目"public",这样局域网中的每个人都可以访问它。
目前我只能通过 http://localhost/project
或他们的虚拟主机名访问我的项目,例如http://myVirtualHostName
.
我需要在我的整个 LAN 中都可以访问这些项目,例如像这样:
http://192.168.1.123/project
或 http://192.168.1.123/myVirtualHostName
.
但是如果我尝试从我自己的客户端或局域网中的另一台计算机访问这些项目,我会得到 403 Forbidden: You don't have permission to access /projectName/ on this server.
。
编辑:
我能够解决第一个问题,我现在可以访问 C:\wamp64\www
下的链接,感谢这个 answer,通过更改 C:\wamp64\bin\apache\apche2.4.33\conf\extra\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>
至
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
...然后重新启动 apache。
现在我可以像这样 http:\192.168.1.123\myProjekt
访问 C:\wamp64\www
中的项目。但我仍然不知道如何使用我的服务器 ip 地址访问虚拟主机。
如果我尝试 http://192.168.1.123/myVhostName
,那么我会得到 Not Found
The requested URL /myVhostName was not found on this server.
,即使每个 virtual host
.
都设置了 Require all granted
我也重新启动了 DNS 服务器。
我该如何解决这个问题?
我正在使用 WAMP 3.1.3。
好的,首先,由于您似乎不了解虚拟主机是什么以及它的用途,所以我将从一些解释开始。
虚拟主机是一种让一个 Apache 为多个站点提供服务的方法,就像您拥有多个 Apache 一样。正确配置后,Apache 会查看传入连接的域名并尝试将其与 VH 定义相匹配。如果可以,它会从该 VH 中定义的 DocumentRoot
提供站点。
如果它无法匹配域名,它将服务于定义文件中的第一个 VH。这就是为什么您首先定义 localhost
并始终将访问权限设置为 Require local
的另一个原因,这将告诉客户端 您没有访问权限 如果他们只是使用您的 WAMPSevrer 的 IP 地址,而不是有效的域名。
从 WAMPServer V3 开始甚至 localhost
被定义为虚拟主机。
所以首先保留 localhost
VH 的定义,就像这样,但是使用 Require local
因为你永远不想允许使用上面的工具远程访问 WAMPServer 主页,因为它不会从远程客户端正确地 运行 因为大多数工具假设 localhost
当来自客户端的 运行 时不存在因为它总是假设在 this PC
即客户端.
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
现在将您的真实站点定义为另一个 VH。我会假设它会被称为 example.local
但在任何地方都可以将其更改为您希望网站真正被调用的任何内容。
<VirtualHost *:80>
ServerName example.local
ServerAlias www.example.local
DocumentRoot "${INSTALL_DIR}/www/example"
<Directory "${INSTALL_DIR}/www/example/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
NOTE: The DocumentRoot
folder does not even have to be in the ${INSTALL_DIR}/www/
it could be anywhere on that disk or even on another drive completely.
现在您还说您有一个现场 DNS 服务器。因此让管理员定义 example.local
并将其指向 PC 运行ning WAMPServer 的 IP 地址。这应该可以通过使用域名 example.local
或 www.example.local
从任何使用该 DNS 服务器的 PC 轻松访问它
If you want a bit more security you might also like to make the Require
more specific, so if the site is only going to be run on one subnet amend the Require all granted
to be
Require ip 10.30.20
Note, I only used the first 3 quartiles of the IPV4 address, which will grant access to any client IP in that segment.
如有任何问题,请发表评论,我会尽快回复您。
我刚从
更改 line:DocumentRoot
c:/wamp64/www
至:
c:/wamp64/www/myproject
它对我有用!
我尝试制作我的项目"public",这样局域网中的每个人都可以访问它。
目前我只能通过 http://localhost/project
或他们的虚拟主机名访问我的项目,例如http://myVirtualHostName
.
我需要在我的整个 LAN 中都可以访问这些项目,例如像这样:
http://192.168.1.123/project
或 http://192.168.1.123/myVirtualHostName
.
但是如果我尝试从我自己的客户端或局域网中的另一台计算机访问这些项目,我会得到 403 Forbidden: You don't have permission to access /projectName/ on this server.
。
编辑:
我能够解决第一个问题,我现在可以访问 C:\wamp64\www
下的链接,感谢这个 answer,通过更改 C:\wamp64\bin\apache\apche2.4.33\conf\extra\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>
至
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
...然后重新启动 apache。
现在我可以像这样 http:\192.168.1.123\myProjekt
访问 C:\wamp64\www
中的项目。但我仍然不知道如何使用我的服务器 ip 地址访问虚拟主机。
如果我尝试 http://192.168.1.123/myVhostName
,那么我会得到 Not Found
The requested URL /myVhostName was not found on this server.
,即使每个 virtual host
.
Require all granted
我也重新启动了 DNS 服务器。
我该如何解决这个问题?
我正在使用 WAMP 3.1.3。
好的,首先,由于您似乎不了解虚拟主机是什么以及它的用途,所以我将从一些解释开始。
虚拟主机是一种让一个 Apache 为多个站点提供服务的方法,就像您拥有多个 Apache 一样。正确配置后,Apache 会查看传入连接的域名并尝试将其与 VH 定义相匹配。如果可以,它会从该 VH 中定义的 DocumentRoot
提供站点。
如果它无法匹配域名,它将服务于定义文件中的第一个 VH。这就是为什么您首先定义 localhost
并始终将访问权限设置为 Require local
的另一个原因,这将告诉客户端 您没有访问权限 如果他们只是使用您的 WAMPSevrer 的 IP 地址,而不是有效的域名。
从 WAMPServer V3 开始甚至 localhost
被定义为虚拟主机。
所以首先保留 localhost
VH 的定义,就像这样,但是使用 Require local
因为你永远不想允许使用上面的工具远程访问 WAMPServer 主页,因为它不会从远程客户端正确地 运行 因为大多数工具假设 localhost
当来自客户端的 运行 时不存在因为它总是假设在 this PC
即客户端.
<VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www"
<Directory "${INSTALL_DIR}/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
现在将您的真实站点定义为另一个 VH。我会假设它会被称为 example.local
但在任何地方都可以将其更改为您希望网站真正被调用的任何内容。
<VirtualHost *:80>
ServerName example.local
ServerAlias www.example.local
DocumentRoot "${INSTALL_DIR}/www/example"
<Directory "${INSTALL_DIR}/www/example/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
NOTE: The
DocumentRoot
folder does not even have to be in the${INSTALL_DIR}/www/
it could be anywhere on that disk or even on another drive completely.
现在您还说您有一个现场 DNS 服务器。因此让管理员定义 example.local
并将其指向 PC 运行ning WAMPServer 的 IP 地址。这应该可以通过使用域名 example.local
或 www.example.local
If you want a bit more security you might also like to make the
Require
more specific, so if the site is only going to be run on one subnet amend theRequire all granted
to be
Require ip 10.30.20
Note, I only used the first 3 quartiles of the IPV4 address, which will grant access to any client IP in that segment.
如有任何问题,请发表评论,我会尽快回复您。
我刚从
更改 line:DocumentRootc:/wamp64/www
至:
c:/wamp64/www/myproject
它对我有用!