虚拟主机子域指向错误的目录

发布于 2024-12-21 08:32:17 字数 2753 浏览 2 评论 0原文

我创建了 2 个虚拟主机 http:// web1.com:2107 指向“/var/www/web1”文件夹,第二个 http:// web2.com:2107 指向“/var/www/web2”。 web2 中的所有子域都工作正常,但对于 web1.com:2107 我只能看到主页。当我尝试从 web1 打开任何子域(例如 http://games.web1.com:2107)时,它指向 web2 的主页,即 /var/www/web2/ 目录

配置是否有问题?

下面是我正在使用的主机的代码

<VirtualHost *:80>
ServerName  web2.com
ServerAdmin [email protected]
ServerAlias http://www.web2.com
DocumentRoot /var/www/web2
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /var/www/web2>
    Options Indexes FollowSymLinks Multiviews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride All
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog    /var/www/web2/error80.log
CustomLog   /var/www/web2/access80.log Combined
</VirtualHost>

<VirtualHost *:2107>
ServerName  web2.com    
ServerAdmin [email protected]
ServerAlias http://www.web2.com
DocumentRoot /var/www/web2
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /var/www/web2>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride All
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

    ErrorLog /var/www/web2/error.log
CustomLog   /var/www/web2/access80.log Combined
LogLevel warn

CustomLog /var/log/apache2/web2.com_access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>

=========================================== =========================

NameVirtualHost *:2107
<VirtualHost *:2107>
    ServerName web1.com
    ServerAlias http://web1.com
    DocumentRoot /var/www/web1
    <Directory /var/www/web1/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
    </Directory>
    ErrorLog        /var/www/web1/error.log
    CustomLog       /var/www/web1/access.log Combined
</VirtualHost>

I created 2 virtual hosts http:// web1.com:2107 pointing to "/var/www/web1" folder and second http:// web2.com:2107 pointing to "/var/www/web2". all subdomains in web2 are working fine, But in case of web1.com:2107 i am able to see only home page. when i try to open any subdomain from web1 like http:// games.web1.com:2107 it points to web2's home page ie /var/www/web2/ directory

Is there anything wrong in configuration ?

below is the code for hosts i am using

<VirtualHost *:80>
ServerName  web2.com
ServerAdmin [email protected]
ServerAlias http://www.web2.com
DocumentRoot /var/www/web2
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /var/www/web2>
    Options Indexes FollowSymLinks Multiviews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride All
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog    /var/www/web2/error80.log
CustomLog   /var/www/web2/access80.log Combined
</VirtualHost>

<VirtualHost *:2107>
ServerName  web2.com    
ServerAdmin [email protected]
ServerAlias http://www.web2.com
DocumentRoot /var/www/web2
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /var/www/web2>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride All
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

    ErrorLog /var/www/web2/error.log
CustomLog   /var/www/web2/access80.log Combined
LogLevel warn

CustomLog /var/log/apache2/web2.com_access.log combined

Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>

</VirtualHost>

===================================================================

NameVirtualHost *:2107
<VirtualHost *:2107>
    ServerName web1.com
    ServerAlias http://web1.com
    DocumentRoot /var/www/web1
    <Directory /var/www/web1/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
    </Directory>
    ErrorLog        /var/www/web1/error.log
    CustomLog       /var/www/web1/access.log Combined
</VirtualHost>

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

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

发布评论

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

评论(4

隱形的亼 2024-12-28 08:32:18

更改 Apache Conf 后,必须重新启动该服务。不确定这是否是问题所在,但检查一下总没有坏处;)

After you change an Apache Conf, you have to restart the service. Not sure if that was the problem, but it never hurts to check ;)

风向决定发型 2024-12-28 08:32:18

好吧,我遇到了一半的问题,HOSTS 文件中留下了条目,因此该页面仍然可用,并且删除了主机名条目。现在一半的问题仍然存在。现在我又创建了一个主机条目并指向差异位置,但仍然指向旧位置:(

Well i got the problem half, there was entry left behind in HOSTS file so that page was still available with deleted host name entry. Now the half problem still there. now i created one more host entry and pointed to diff location but still its pointing to old location :(

ゝ杯具 2024-12-28 08:32:18

对于存在 SSL 问题和错误目录的 Cloudflare 用户:

将 Crypto 的 SSL 模式从 Flexible 更改为 Full

这对我有帮助。

For Cloudflare users wich have some issues with SSL and a wrong directory:

Change the SSL Mode at Crypto from Flexible to Full.

This helped me.

小苏打饼 2024-12-28 08:32:17

当您有多个 VirtualHost 时,其中之一就是默认 VirtualHost。
它是包含 VirtualHost 定义的文件中按字母顺序排列的第一个文件。

当您删除虚拟主机时。如果您的 Hosts 文件或 DNS 记录中仍有条目,则当在 Apache 服务器上执行查询时,如果找不到正确的 VirtualHost(ServerName 或 ServerAlias),则会采用默认的 VirtualHost 来处理答案。

当您添加新的 VirtualHost 时,如果您在 ServerName 或 ServerAlias 中犯了错误,您还将拥有默认的 VH。

更新

现在问题已经完成,我可以看到您没有以正确的方式使用 ServerAlias。您的所有子域都应在 ServerAlias 指令中列出,不带 http://
所以你应该:

ServerName web1.com
ServerAlias www.web1.com
ServerAlias games.web1.com

你可以尝试 *.web1.com。
否则,当您使用未列出的名称时,将使用默认虚拟主机(此处虚拟主机 web2.com 是之前定义的,因此它是此端口上的默认虚拟主机)

When you have several VirtualHosts one of them is the default VirtualHost.
It's the first one in alphabetic order of the file containing the definition of the VirtualHost.

When you remove a VirtualHost. If you still have an entry in the Hosts file or a DNS record, when the query is performed on your Apache server, if it cannot find the right VirtualHost (ServerName or ServerAlias), then the default one is taken to process the answer.

When you add a new VirtualHost, if you make a mistake in the ServerName or ServerAlias you'll also have the default VH.

Update

Now that the question is complete I can see you are not using ServerAlias in the right way. All your subdomains should be listed in ServerAlias directives, without the http://
So you should have:

ServerName web1.com
ServerAlias www.web1.com
ServerAlias games.web1.com

You could maybe try a *.web1.com.
Else when you use a name which is not listed the default vhost is used (and here vhost web2.com is defined before so it's the default one on this port)

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