无法使用 wampserver 创建 URL

Unable to create URL with wampserver

我正在尝试为通过 wampserver 托管的站点创建一个 URL,但无论我做什么,我都无法让 URL 工作。该站点在线,因为我可以通过服务器 IP 地址进行连接。

(我还应该提一下,这个网站只能在内部网上找到)

主机文件:

# 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 localhost
127.0.0.1 www.socialclub.com    #also tried public/private IP, still only works locally

vhosts.conf:

# Virtual Hosts
#
# Required modules: mod_log_config

# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at 
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#

<VirtualHost *:80>
    ServerName localhost
    DocumentRoot "E:\Data\Users Apps\wamp\www\socialclub"
</VirtualHost>


<Directory "E:\Data\Users Apps\wamp\www\socialclub">
    AllowOverride All
    Order Allow,Deny
    Allow from all
    Options Indexes FollowSymLinks Includes ExecCGI
</Directory>
<VirtualHost *:80>
    DocumentRoot "E:\Data\Users Apps\wamp\www\socialclub"
    ServerName www.socialclub.com
</VirtualHost>

我看过的每份指南都说这应该有效,但它只在本地有效。我需要做什么才能使 URL 在其他计算机上工作?

好的,我认为问题是您不了解 HOSTS 文件的用途及其范围。

HOSTS 文件只影响它所在的​​单台 PC。它用于在启动时为 windows DNS 缓存设置种子。因此,无论您在此文件中放入什么,都不会影响您内联网中的任何其他 PC。

有几个解决方案:

假设您的 PC 运行 WAMPServer 的 IP 地址为 192.168.1.10:

  • 您可以转到您的 Intranet 中的每台 PC 并将此更改更改为 每台 PC 上的 HOSTS 文件

    192.168.1.10 socialclub.com
    

    人们通常认为这太麻烦了,尤其是当他们有超过 5-6 台 PC 时 mod

  • 您可以安装本地 DNS 服务器,或使用现有的 本地 DNS 服务器。那么只要你内网的所有PC都 使用该 DNS 服务器,您将域名添加到该 DNS 服务器。

    人们通常认为这是个好主意,但要做到这一点可能会非常复杂,而且不能松散地访问网络上的真实 DNS 服务器

我建议对您的 httpd-vhost.conf 文件进行一些更改

首先让localhost指向原来的wampserver主页,但只允许从PC运行WAMPServer访问。主页上的工具对 debug/diagnostics/etc 非常有用,但只允许从 PC 运行 WAMPServer 访问本地主机。

其次将 <Directory></Directory> 块放入虚拟主机定义中。这允许您使每个虚拟主机的安全性特定于该虚拟主机。

# Should be the first VHOST definition so that it is the default virtual host
# Also access rights should remain restricted to the local PC and the local network
# So that any random ip address attack will recieve an error code and not gain access

<VirtualHost *:80>
    DocumentRoot "c:/wamp/www"
    ServerName localhost
    <Directory  "c:/wamp/www">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "E:\Data\Users Apps\wamp\www\socialclub"
    ServerName www.socialclub.com
    <Directory "E:\Data\Users Apps\wamp\www\socialclub">
        AllowOverride All
        Options Indexes FollowSymLinks Includes ExecCGI
        # assuming your subnet equates to this range
        # and you are using Apache 2.4.x
        # its not necessary to allow access from all in an intranet
        # in fact it might be dangerous
        Require ip 192.168.1             

    </Directory>
</VirtualHost>