Apache 2的网站,可用的配置 [英] Apache 2 Sites-Available Configuration

查看:151
本文介绍了Apache 2的网站,可用的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图写5个网站的所有这一切在一个IP地址,一个Apache,服务器上。

I am trying to write about 5 websites all on one Apache server which is all on one IP address.

例如:


  • /无功/网络/ site1的

  • /无功/网络/站点2

  • /无功/网络/ site3

  • /无功/网络/ site4

  • /无功/网络/ site5

不过,如果我创建只是用,例如站点2的链接。的index.php,你希望它在/var/www/site2/index.php看...但它实际上解析为/var/www/index.php。

However, if I create a link on site 2 just using, for example. /index.php, you would expect it to look in /var/www/site2/index.php... but it actually resolves to /var/www/index.php.

反正是有设置Apache的要知道,不同的站点文件夹需要的行为,并解析为单独的文件夹?

Is there anyway of setting up Apache to know that the separate site folders need to behave and resolve to the separate folders?

这是目前我的网站可用文件。一个相当默认的设置,我相信:

This is my sites-available file at the moment. A fairly default setup I believe:

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            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 None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

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

任何帮助将是preciated。

Any help would be apreciated.

感谢,请你。

安德鲁·巴洛

推荐答案

您需要的&LT内ServerName指令;虚拟主机&GT; 。根据浏览器请求(它会告诉虚拟主机是目前正在使用的服务器,如果您的客户端访问 http://site1.example.com http://site2.example.com 时,它们将连接到相同的IP,因此,服务器,但请求包含原始请求URL)。
你必须复制你的&LT;虚拟主机&GT; 块有一个托管的每个部位。每块将其服务器名称和DocumentRoot的主要区别。
你可以用apache2ctl -S可以看到Apache如何了解你的虚拟主机设置。

You need a ServerName directive inside the <VirtualHost>. It will tell the server which virtual host is currently in use depending on the browser request (if your client access http://site1.example.com or http://site2.example.com, they will connect to the same IP, hence server, but the request contains the original request url). You'll have to duplicate your <VirtualHost> block to have one per hosted site. Each block will differ by their ServerName and DocumentRoot mainly. You can use "apache2ctl -S" to see how apache understood your virtual host settings.

您可以使用一个文件,这样的内容:

You can use a single file with this kind of content :

<VirtualHost *:80>
  ServerName site1.myserver.com
  DocumentRoot /var/www/site1
  ...
</VirtualHost>

<VirtualHost *:80>
  ServerName site2.myserver.com
  DocumentRoot /var/www/site2
  ...
</VirtualHost>

<VirtualHost *:80>
  ServerName site3.myserver.com
  DocumentRoot /var/www/site3
  ...
</VirtualHost>

<VirtualHost *:80>
  ServerName site4.myserver.com
  DocumentRoot /var/www/site4
  ...
</VirtualHost>

<VirtualHost *:80>
  ServerName site5.myserver.com
  DocumentRoot /var/www/site5
  ...
</VirtualHost>

当然,也许确保所有这些名称的DNS您的IP结束。它不必是子域,只要他们降落在你的服务器IP,你有这方面的对应服务器名。如果你需要额外的名字一个网站,你可以将它们添加ServerAlias​​ secondname.myserver.com thirdname.myserver.com的服务器名称

Of course, maybe sure that the dns for all of those name ends up on your IP. It needs not to be subdomains as long as they land on your server ip and you have a correspond ServerName for it. If you need extra names for a single site, you can add them with "ServerAlias secondname.myserver.com thirdname.myserver.com" below ServerName

这篇关于Apache 2的网站,可用的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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