如何在一个Apache实例上运行多个站点 [英] How to run multiple sites on one apache instance

查看:218
本文介绍了如何在一个Apache实例上运行多个站点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

兜兜花了几个小时以下每导游,我可以在网络上找到。

Spent hours going in circles following every guide I can find on the net.

我想有一个Apache实例上运行两个网站,这样的事情 -
192.168.2.8/site1

192.168.2.8/site2

I want to have two sites running on a single apache instance, something like this - 192.168.2.8/site1 and 192.168.2.8/site2

我一直转圈圈,但此刻我有两个conf文件中的网站可用(符号链接到网站启用​​ - )'看起来像这样 -

I’ve been going round in circles, but at the moment I have two conf files in ‘sites-available (symlinked to sites-enabled)’ that look like this-

<VirtualHost *:2000>

ServerAdmin webmaster@site1.com
ServerName site1
ServerAlias site1

# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /home/user/site1/

# CGI Directory
ScriptAlias /cgi-bin/ /home/user/site1/cgi-bin/

Options +ExecCGI

# Logfiles
ErrorLog /home/user/site1/logs/error.log
CustomLog /home/user/site1/logs/access.log combined

</VirtualHost>

<VirtualHost *:3000>

ServerAdmin webmaster@site2.com
ServerName site2
ServerAlias site2

# Indexes + Directory Root.
DirectoryIndex index.html
DocumentRoot /home/user/site2/

# CGI Directory
ScriptAlias /cgi-bin/ /home/user/site2/cgi-bin/

Options +ExecCGI

# Logfiles
ErrorLog /home/user/site2/logs/error.log
CustomLog /home/user/site2/logs/access.log combined

</VirtualHost>

http.conf中看起来是这样的 -

http.conf looks like this-

NameVirtualHost *:2000
NameVirtualHost *:3000

目前,我得到这个错误 -

At the moment I’m getting this error-

[error] VirtualHost *:80 — mixing * ports and non-* ports with a NameVirtualHostaddress is not supported, proceeding with undefined results

Ports.conf看起来像这样 - (虽然没有导游提到任何需要编辑这个)

Ports.conf looks like this – (although no guides have mentioned any need to edit this)

NameVirtualHost *:80

Listen 80
<IfModule mod_ssl.c>
# If you add NameVirtualHost *:443 here, you will also have to change
# the VirtualHost statement in /etc/apache2/sites-available/default-ssl
# to <VirtualHost *:443>
# Server Name Indication for SSL named virtual hosts is currently not
# supported by MSIE on Windows XP.
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>

谁能给一些简单的指令得到这个运行?我发现每一个导游说,做不同的方式,每一个会导致​​不同的错误。我明明做错事,但已经找到了什么,可能是没有明确的解释。

Can anyone give some simple instructions to get this running? Every guide I’ve found says to do it a different way, and each one leads to different errors. I'm obviously doing something wrong but have found no clear explanation of what that might be.

只是想在2000端口一个网站访问,并在端口3000的其他无障碍(或什么的,只是拿起这些端口来测试)。

Just want one site accessible on port 2000 and the other accessible on port 3000 (or whatever, just picked those ports to test with).

我运行Ubuntu服务器12.04 ...

I’m running Ubuntu server 12.04…

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

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

接着一个引导...

现在我在网站可用此设置:

I've now set this up in sites-available:

<VirtualHost *:80>
    DocumentRoot "/home/user/site1/"
    ServerName 192.168.2.10/site1
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/home/user/site2/"
    ServerName 192.168.2.10/site2
</VirtualHost>

已经将这个在apache2.conf:

Have set this in apache2.conf:

ServerName site1
ServerName site2

已经加入这个ports.conf:

Have added this to ports.conf:

Listen 192.168.2.10:80

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

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

现在的工作,我把这个在conf文件中启用了站点:

It now works, I put this in a conf file in site-enabled:

<VirtualHost *:81>
    DocumentRoot "/home/user/site1/"
    ServerName site1
</VirtualHost>

<VirtualHost *:82>
    DocumentRoot "/home/user/site2/"
    ServerName site2
</VirtualHost>

我有这样的ports.conf:

I have this in ports.conf:

Listen *:80
Listen *:81
Listen *:82

我有这样的apache2.conf:

I have this in apache2.conf:

ServerName site1
ServerName site2

我没有在我刚刚得到它通过试错的一整天工作的指导找到这个,所以我不知道这是不是一个很好的解决方案。但它至少工作,我怎么想了。

I didn't find this in any guides I just got it working through an entire day of trial and error so I don't know if this is a good solution. But it's at least working how I want it to now.

推荐答案

您的问题是混合了几个不同的概念。你开始了说你想跑使用相同的域在同一台服务器上的网站,但在不同的文件夹中。这并不需要任何特殊的设置。一旦你获得了单域运行,您只需创建一个文档根目录下的文件夹。

Your question is mixing a few different concepts. You started out saying you wanted to run sites on the same server using the same domain, but in different folders. That doesn't require any special setup. Once you get the single domain running, you just create folders under that docroot.

根据你的问题,你真正想要做的是运行自己的域名在同一服务器上各种网站的其余部分。

Based on the rest of your question, what you really want to do is run various sites on the same server with their own domain names.

你会发现在该主题的最好的文档是虚拟主机文档。

The best documentation you'll find on the topic is the virtual host documentation in the apache manual.

有两种类型的虚拟主机的:名称为基础和基于IP的。基于名称的,您可以使用一个单一的IP地址,而基于IP的需要为每个站点不同的IP。基于以上您的描述,您想使用基于域名的虚拟主机。

There are two types of virtual hosts: name-based and IP-based. Name-based allows you to use a single IP address, while IP-based requires a different IP for each site. Based on your description above, you want to use name-based virtual hosts.

你都拿到最初的错误是由于这样的事实,你正在使用比了NameVirtualHost 行不同的端口。如果你真的想从网站80比其他港口提供服务,你需要为每个端口了NameVirtualHost 项。

The initial error you were getting was due to the fact that you were using different ports than the NameVirtualHost line. If you really want to have sites served from ports other than 80, you'll need to have a NameVirtualHost entry for each port.

假设你是从头开始,这是简单得多比它看起来可能。

Assuming you're starting from scratch, this is much simpler than it may seem.

您需要做的第一件事是让Apache,你要使用基于域名的虚拟主机。

The first thing you need to do is tell apache that you're going to use name-based virtual hosts.

NameVirtualHost *:80

现在阿帕奇知道你想做什么,你可以设置你的虚拟主机定义:

Now that apache knows what you want to do, you can setup your vhost definitions:

<VirtualHost *:80>
    DocumentRoot "/home/user/site1/"
    ServerName site1
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/home/user/site2/"
    ServerName site2
</VirtualHost>

请注意,只要你想在同一端口上,你可以运行尽可能多的网站。在服务器名称是不同的,就足以告诉Apache使用的虚拟主机。此外,服务器名称指令总是域/主机名和不应该包括路径。

Note that you can run as many sites as you want on the same port. The ServerName being different is enough to tell Apache which vhost to use. Also, the ServerName directive is always the domain/hostname and should never include a path.

如果你决定运行80以外的端口上的网站,你总能访问该网站时,在URL中包含的端口号。因此,而不是去 http://example.com 你将不得不去的 http://example.com:81

If you do decide to run sites on a port other than 80, you'll always have to include the port number in the URL when accessing the site. So instead of going to http://example.com you would have to go to http://example.com:81

这篇关于如何在一个Apache实例上运行多个站点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆