简体   繁体   English

Apache服务器上的多个域

[英]Multiple domains on apache server

First a quick disclaimer, I'm not a 'server guy' or a 'unix pro' or anything like that, I'm a web programmer who got stuck doing server works since I ran linux (ubuntu) on my netbook. 首先是一个快速的免责声明,我不是一个“服务器专家”或“ unix专业人士”或类似的东西,我是一个网络程序员,因为我在上网本上运行linux(ubuntu)以来一直从事服务器工作。

I'm trying to set up an apache server running on Debian to automagically serve multiple domains, each domain needs to have its own directory in /var/www. 我试图设置在Debian上运行的apache服务器以自动服务多个域,每个域都必须在/ var / www中拥有自己的目录。

Since this is the last thing I do for this company I really need it to be easy for my successor (who is even more a beginner at servers than I am), to create more domains without having to muck around with ssh or /etc/apache2/sites-available, so what I'm looking for is basically any magic mumbo-jumbo in default (or apt-get, or conf.d) that makes the server start serving any domain that has a matching folder in /var/www they will ofcourse have to initiate domain transfers the usual way. 因为这是我为这家公司所做的最后一件事,所以我真的需要它对我的继任者(比我更像是服务器的初学者)来说很容易,以便创建更多的域而不必使用ssh或/ etc / apache2 / sites-available,所以我要寻找的基本上是默认情况下的任何魔术mumbo-jumbo(或apt-get或conf.d),它使服务器开始为/ var /中具有匹配文件夹的任何域提供服务www,他们当然必须以通常的方式启动域名转移。

I have no problem setting up domains individually. 我没有问题单独设置域。

Ick... hope the above makes sense to someone. 恩...希望以上对某人有意义。

To serve multiple domains from Apache, you'll need Apache Virtual Hosts. 要从Apache服务多个域,您将需要Apache虚拟主机。 You can start serving any domain that has a matching folder in /var/www" with Apache Virtual Hosts using mod_vhost_alias . 您可以使用mod_vhost_alias开始使用Apache Virtual Hosts为/ var / www“中具有匹配文件夹的任何域提供服务。

The following configuration will take the fully-qualified domain name (like www.example.org) and use it as the variable '%0'. 以下配置将使用完全限定的域名(例如www.example.org),并将其用作变量'%0'。 So, to serve out 'www.example.org', you create a directory at /var/www/www.example.org/docs , and place your HTML content there. 因此,要提供“ www.example.org”,请在/var/www/www.example.org/docs中创建一个目录,并将HTML内容放在此处。 Your Cgi script will go in /var/www/www.example.org/cgi-bin/ 您的Cgi脚本将进入/var/www/www.example.org/cgi-bin/

<VirtualHost 192.168.1.100:80>

# get the server name from the Host: header
UseCanonicalName Off

VirtualDocumentRoot /var/www/%0/docs
VirtualScriptAlias /var/www/%0/cgi-bin

</VirtualHost>

Then, point 'www.example.org' to '192.168.1.100', and Apache will happily serve that Virtual Host. 然后,将“ www.example.org”指向“ 192.168.1.100”,Apache将很高兴为该虚拟主机提供服务。

Untested Code with flavor of Ubuntu 未经测试的具有Ubuntu风格的代码

sudo a2enmod rewrite
vi /etc/apache/sites-enabled/000-default

NameVirtualHost *
<VirtualHost *>
        DocumentRoot /var/www/
        RewriteEngine On
        RewriteRule ^(.*)$ %{HTTP_HOST}/$1
</VirtualHost>


sudo /etc/inid.d/apache2 restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM