在一台 wamp 服务器中托管多个站点

发布于 2024-11-04 06:14:24 字数 1527 浏览 0 评论 0原文

我有两个不同的站点,我想通过 wamp 服务器托管它们,例如,我的第一个站点是 http://one。 gov.ae 第二个是 http://two.gov.ae

我想要的是当我输入第一个站点时,它应该打开第一个站点的索引,当我输入第二个站点时,它应该打开索引应该打开第二个站点。

但无论我输入什么,它都会打开第一个索引

,但是我将两者都添加到 httpd-vhosts.con 中,并取消注释 http.conf 中的以下行

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

所以任何人都可以告诉我在这种情况下我可以做什么,

这是我的 httpd-vhosts .conf代码

<VirtualHost 172.20.10.121:80>
   # ServerAdmin admin@localhost
     DocumentRoot "C:/wamp/www"
     ServerName localhost
   # ServerAlias www.dummy-host.localhost
   # ErrorLog "logs/dummy-host.localhost-error.log"
   # CustomLog "logs/dummy-host.localhost-access.log" common
</VirtualHost>

<VirtualHost 172.20.10.121:8080>
   # ServerAdmin [email protected]
     ServerName meera.am.gov.ae
     DocumentRoot "c:wamp/www/meera"
     Directoryindex index.php index.html
   # ErrorLog "logs/dummy-host2.localhost-error.log"
   # CustomLog "logs/dummy-host2.localhost-access.log" common
</VirtualHost>

我在httpd文件中注释了以下内容

# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<FilesMatch "^\.ht">
  #  Order allow,deny
  #  Deny from all
  # Satisfy All
</FilesMatch>

I have two different sites and i want to host both of them through wamp server for example, my first site is http://one.gov.ae and the second one is http://two.gov.ae

what I want is when I type the first site it should open the index for the first one and i when i type the second one it should open the second site.

but whatever I type it open the index for the first one

however I add both sits in httpd-vhosts.con and uncomment the following line in http.conf

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

So anyone can tell me what I can do in such situation

here is my httpd-vhosts.conf code

<VirtualHost 172.20.10.121:80>
   # ServerAdmin admin@localhost
     DocumentRoot "C:/wamp/www"
     ServerName localhost
   # ServerAlias www.dummy-host.localhost
   # ErrorLog "logs/dummy-host.localhost-error.log"
   # CustomLog "logs/dummy-host.localhost-access.log" common
</VirtualHost>

<VirtualHost 172.20.10.121:8080>
   # ServerAdmin [email protected]
     ServerName meera.am.gov.ae
     DocumentRoot "c:wamp/www/meera"
     Directoryindex index.php index.html
   # ErrorLog "logs/dummy-host2.localhost-error.log"
   # CustomLog "logs/dummy-host2.localhost-access.log" common
</VirtualHost>

I comment the following in httpd file

# The following lines prevent .htaccess and .htpasswd files from being 
# viewed by Web clients. 
#
<FilesMatch "^\.ht">
  #  Order allow,deny
  #  Deny from all
  # Satisfy All
</FilesMatch>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

飘逸的'云 2024-11-11 06:14:24

但是无论我输入什么,它都会打开第一个的索引

所以我猜你的服务器也会侦听端口 8080。你没有提到那部分。

问题可能是您还启用了基于名称的虚拟主机,例如:

NameVirtualHost *

... 或

NameVirtualHost 172.20.10.121

这样 Apache 通过主机名(Host 请求标头)来识别主机。如果没有发送主机或在配置中找不到匹配的ServerName,则第一个主机(默认主机)将处理该请求。

尽管我强烈建议您使用基于名称的虚拟主机,而不是这种疯狂的端口。使用诸如 mysite.testjopbsite.testprojectname.test 等名称。这样它们都可以监听端口 80,你必须为所有主机定义ServerName,使用我上面的示例之一启用基于名称的虚拟主机,然后在以下

c:\windows\system32\drivers\etc\hosts

文件中定义您的 NS 条目:

编辑:

你的 vhosts.conf 中应该有类似这样的内容:

NameVirtualHost *

<VirtualHost *>
     ServerName mysite.test

     DocumentRoot "C:/www/mysite.test"
     Directoryindex index.php index.html
</VirtualHost>

<VirtualHost *>
     ServerName theothersite.test

     DocumentRoot "C:/www/theothersite.test"
     Directoryindex index.php index.html
</VirtualHost>

but whatever I type it open the index for the first one

So I guess your server does listen on the port 8080 too. You did not mention that part.

The problem could be that you also enabbled name based virtual hosting with something like:

NameVirtualHost *

... or

NameVirtualHost 172.20.10.121

This way Apache is identifying hosts by hostname (the Host request header). If no host is sent or no matching ServerName found in config, the first host (the default host) will handle the request.

Although instead of this port madness I strongly recommend you using name-based virtual hosts. With names like mysite.test or jopbsite.test or projectname.test etc. This way they can all listen on port 80, you have to define the ServerName for all of the hosts, enbale name based virtual hosting with one of my examples above then define your NS entries in:

c:\windows\system32\drivers\etc\hosts

file.

Edit:

ou should have something like this in your vhosts.conf:

NameVirtualHost *

<VirtualHost *>
     ServerName mysite.test

     DocumentRoot "C:/www/mysite.test"
     Directoryindex index.php index.html
</VirtualHost>

<VirtualHost *>
     ServerName theothersite.test

     DocumentRoot "C:/www/theothersite.test"
     Directoryindex index.php index.html
</VirtualHost>
晒暮凉 2024-11-11 06:14:24

有很多这方面的详细教程。我有一段时间没有使用 WAMP,但这是我上次使用时使用的指南: http://cesaric .com/?p=255

There are lots of detailed tutorials on this. I haven't used WAMP in a while but this is the guide I used when I did last: http://cesaric.com/?p=255

无名指的心愿 2024-11-11 06:14:24

您需要修改 .conf 以适应两个单独的虚拟主机。

在下面的示例中,您基本上需要设置 ServerName、ServerAlias 和其他变量才能将它们分开。

<VirtualHost *>
    ServerAdmin [email protected]
    ServerName  www.example.org
    ServerAlias example.org

    # Indexes + Directory Root.
    DirectoryIndex index.html
    DocumentRoot /home/www/www.example.org/htdocs/
</VirtualHost>

<VirtualHost *>
    ServerAdmin [email protected]
    ServerName  www.example.com
    ServerAlias example.com

    # Indexes + Directory Root.
    DirectoryIndex index.html
    DocumentRoot /home/www/www.example.com/htdocs/
</VirtualHost>

希望有帮助。请务必在修改 .conf 文件之前停止 Apache,然后再次启动它。

You'll need to modify your .conf to account for two separate virtual hosts.

In the below example you'll basically need to set the ServerName, ServerAlias and other variables in order to separate them.

<VirtualHost *>
    ServerAdmin [email protected]
    ServerName  www.example.org
    ServerAlias example.org

    # Indexes + Directory Root.
    DirectoryIndex index.html
    DocumentRoot /home/www/www.example.org/htdocs/
</VirtualHost>

<VirtualHost *>
    ServerAdmin [email protected]
    ServerName  www.example.com
    ServerAlias example.com

    # Indexes + Directory Root.
    DirectoryIndex index.html
    DocumentRoot /home/www/www.example.com/htdocs/
</VirtualHost>

Hope that helps. Be sure to stop Apache before modifying the .conf file and then start it again.

他是夢罘是命 2024-11-11 06:14:24

不久前我遇到了这个问题,我发现这是一个愚蠢的错误,我没有在 httpd 服务器上重新启动。

如果您的 PATH 中链接了 /bin 目录,您可以尝试从命令提示符运行此命令:

httpd -k restart

希望它有帮助!干杯:)

I had this problem a while back and I found out that it was a silly mistake that I didn't do a restart on the httpd server.

You could try running this from a command prompt if you have the /bin directory linked in your PATH:

httpd -k restart

Hope it helps ! Cheers :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文