Apache 2 站点可用配置 [英] Apache 2 Sites-Available Configuration

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

问题描述

我试图在一台 Apache 服务器上编写大约 5 个网站,而这些服务器都在一个 IP 地址上.

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

例如:

  • /var/www/site1
  • /var/www/site2
  • /var/www/site3
  • /var/www/site4
  • /var/www/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>

感谢任何帮助.

谢谢你.

安德鲁·巴洛

推荐答案

您需要 中的 ServerName 指令.它会根据浏览器请求告诉服务器当前正在使用哪个虚拟主机(如果您的客户端访问 http://site1.example.comhttp://site2.example.com,它们将连接到相同的IP,因此是服务器,但请求包含原始请求 url).您必须复制您的 <VirtualHost> 块,以便每个托管站点都有一个.每个块的主要区别在于它们的 ServerName 和 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 上并且您有相应的 ServerName 即可.如果您需要为单个站点提供额外的名称,您可以在 ServerName 下方添加ServerAlias secondname.myserver.comthirdname.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天全站免登陆