apache将单个子域映射到文件夹

时间:2021-05-02 00:29:18

In my /var/www I have a number of sites (goodsite, badsite, uglysite). Right now they are accessed by mydomain.com/goodsite, etc..

在我的/ var / www中我有很多站点(goodsite,badsite,uglysite)。现在可以通过mydomain.com/goodsite等访问它们。

What I want is for one site in particuar, uglysite, to be accessed by uglysite.mydomain.com - the others remain as they are.

我想要的是uglysite.mydomain.com访问一个特别是uglysite的网站 - 其他网站保持原样。

I have tried all sorts of ways of fiddling with the.htaccess (in /var/www). Note I have mod-rewrite enabled and mod vhost-alias enabled.

我尝试了各种摆弄.htaccess(在/ var / www中)的方法。注意我启用了mod-rewrite并启用了mod vhost-alias。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^uglysite\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/uglysite/
RewriteRule ^(.*)$ /uglysite/$1 [L]

What ends up happening is that both mydomain.com and uglysite.mydomain.com always map to the same thing (i.e., the index at /var/www). I tried adding in a new virtual host, and was surprised to find that uglysite.mydomain.com mapped correctly, but then mydomain.com also mapped directly to uglysite as well.

最终发生的是mydomain.com和uglysite.mydomain.com都始终映射到同一个东西(即/ var / www处的索引)。我尝试添加一个新的虚拟主机,并且惊讶地发现uglysite.mydomain.com正确映射,但是mydomain.com也直接映射到uglysite。

<Virtualhost uglysite.mydomain.com:80>
       ServerName uglysite.mydomain.com
       ServerAdmin www@localhost
       DocumentRoot "/var/www/"
       AccessFileName .htaccess
       <Directory "/var/www/uglysite">
               Order allow,deny
               Allow from All
               AllowOverride All
       </Directory>
</VirtualHost>

The above was added to my sites-enabled/000-default file. This got uglysite.mydomain.com to work properly, but then mydomain.com mapped to the same thing!

以上内容已添加到我的网站启用/ 000默认文件中。这让uglysite.mydomain.com正常工作,但是mydomain.com映射到了同样的东西!

Is there a straightforward way to do what I'm intending to do?? Thanks in advance.

有没有直接的方式去做我打算做的事情?提前致谢。

1 个解决方案

#1


16  

You should be making uglysite into a second file instead of modifying 000-default

你应该将uglysite变成第二个文件,而不是修改000-default

So, take a copy of the 000-default file, change the subdomain as you have done up there and modify the directory to /path/to/site

因此,获取000-default文件的副本,更改子域,并将目录修改为/ path / to / site

000-default:

000默认:

<Virtualhost *:80>
       ServerName mydomain.com
       ServerAdmin www@localhost
       ServerAlias mydomain.com
       DocumentRoot "/var/www/goodsite"
       AccessFileName .htaccess
       <Directory "/var/www/goodiste">
               Order allow,deny
               Allow from All
               AllowOverride All
       </Directory>
</VirtualHost>

uglysite:

uglysite:

<Virtualhost *:80>
       ServerName uglysite.mydomain.com
       ServerAlias uglysite.mydomain.com
       ServerAdmin www@localhost
       DocumentRoot "/var/www/uglysite"
       AccessFileName .htaccess
       <Directory "/var/www/uglysite">
               Order allow,deny
               Allow from All
               AllowOverride All
       </Directory>
</VirtualHost>

Also note that in the above samples, I have modified the DocumentRoot to point to the directory that you want file served from

另请注意,在上面的示例中,我修改了DocumentRoot以指向您希望从中提供文件的目录

EDIT: virtualhosts set to *:80 since your sites point to your own ip anyway

编辑:虚拟主机设置为*:80,因为您的站点无论如何都指向您自己的IP

#1


16  

You should be making uglysite into a second file instead of modifying 000-default

你应该将uglysite变成第二个文件,而不是修改000-default

So, take a copy of the 000-default file, change the subdomain as you have done up there and modify the directory to /path/to/site

因此,获取000-default文件的副本,更改子域,并将目录修改为/ path / to / site

000-default:

000默认:

<Virtualhost *:80>
       ServerName mydomain.com
       ServerAdmin www@localhost
       ServerAlias mydomain.com
       DocumentRoot "/var/www/goodsite"
       AccessFileName .htaccess
       <Directory "/var/www/goodiste">
               Order allow,deny
               Allow from All
               AllowOverride All
       </Directory>
</VirtualHost>

uglysite:

uglysite:

<Virtualhost *:80>
       ServerName uglysite.mydomain.com
       ServerAlias uglysite.mydomain.com
       ServerAdmin www@localhost
       DocumentRoot "/var/www/uglysite"
       AccessFileName .htaccess
       <Directory "/var/www/uglysite">
               Order allow,deny
               Allow from All
               AllowOverride All
       </Directory>
</VirtualHost>

Also note that in the above samples, I have modified the DocumentRoot to point to the directory that you want file served from

另请注意,在上面的示例中,我修改了DocumentRoot以指向您希望从中提供文件的目录

EDIT: virtualhosts set to *:80 since your sites point to your own ip anyway

编辑:虚拟主机设置为*:80,因为您的站点无论如何都指向您自己的IP