配置httpd.conf以在Apache Red Hat Linux上添加新站点

时间:2015-06-10 16:57:23

标签: linux apache httpd.conf

我安装了apache linux服务器(Red Hat Enterprise Linux Server 5.3版(Tikanga))。它已经用于浏览一些文档。现在我想添加一个新目录(带有html页面),所以无论何时浏览目录,它都可以显示html页面。

但我不确定编辑httpd.conf文件的所有内容

现有的httpd.conf:

enter image description here

当我点击网址" http://servername/eng"它显示文件夹列表。

现在,我想在现有网站上添加一个网站,所以当用户点击网址时,#http://servername/builds"它应该在浏览器中显示一个html页面。我已经添加了我的" index.html"页面位置" / var / www / html / builds /"

为此,我将以下代码添加到 httpd.conf 文件中 enter image description here

请告诉我conf文件中所需的所有修改

1 个答案:

答案 0 :(得分:2)

你可以用几种不同的方式来做。

  1. index.html放入/build

    这要求您具有以下设置:

    DirectoryIndex index.html
    

    (在大多数平台上默认应该存在。)

    为了使其工作,而不是放置新的<Directory>,您应该将build/目录放在包含http://example.com/文件的目录中。例如:

    /var/www/example.com/public_html/eng/
    /var/www/example.com/public_html/builds/
    /var/www/example.com/public_html/builds/index.html
    
  2. build/存储在完全与example.com无关的文件夹中,但仍然可以通过example.com/builds

    与其联系

    为此,您需要重写URL,以便example.com/builds将用户重定向到最终的URL。这最容易通过mod_rewrite实现。您在Apache的配置中启用了mod_rewrite模块,确保example.com可以.htaccess个文件,以确保在AllowOverride&#中正确example.com条目39; s <Directory>配置,创建/var/www//example.com/public_html/.htaccess(或类似)文件,并填写所需的RewriteEngine OnRewriteRule。有关Internet和文档中mod_rewrite的更多信息。

  3. 完全分离虚拟服务器,例如builds.example.com/

    在这种情况下,您正在寻找的是虚拟服务器。这些未在httpd.conf或配置本身中定义,但通常具有专用目录。

    例如,要添加适用于端口80的builds.example.com,您需要创建以下条目:

    <VirtualHost *:80>
        ServerName builds.example.com
        DocumentRoot /var/www/builds.example.com/public_html/
    </VirtualHost>
    

    在哪里放这个?嗯,这取决于平台。对于Debian,您可以将其放在/etc/apache2/sites-available/中的新文件中,例如/etc/apache2/sites-available/example.com中的/etc/apache2/sites-available及其符号链接(在Debian上,您可以使用a2ensite <NAME_OF_FILE>轻松完成此操作。在您的平台上,此过程可能会有所不同,请查阅(&#34;在&#34;上添加虚拟服务器将是一个开始。。添加虚拟服务器后,您需要重新加载Apache配置。

  4. 如果这符合您的问题,请告诉我,如果没有,我会相应地编辑答案。