【问题标题】:How to add a second site in httpd.conf如何在 httpd.conf 中添加第二个站点
【发布时间】:2018-05-31 17:16:45
【问题描述】:

我在我的 CentOs 7 Apache 服务器中使用 httpd.conf 的以下配置来运行“site1”:

ServerRoot "/etc/httpd"
Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin root@localhost
ServerName locahost:80
<Directory />
    AllowOverride none
    Require all denied
</Directory>
DocumentRoot "/var/www/html/site1"
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>
<Directory "/var/www/html/site1">
        Options FollowSymLinks
        AllowOverride all
        Order allow,deny
        Allow from all
</Directory>
<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
<Files ".ht*">
    Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "logs/access_log" combined
</IfModule>
<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
</IfModule>
<Directory "/var/www/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>
<IfModule mime_module>
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
</IfModule>
AddDefaultCharset UTF-8
<IfModule mime_magic_module>
    MIMEMagicFile conf/magic
</IfModule>
EnableSendfile on
IncludeOptional conf.d/*.conf

当我访问“http://localhost”时,site1 及其子页面/子文件夹正常工作。 我现在希望能够显示第二个网站:当访问“http://localhost/site2”时,我想显示保存在“/test”下的文件“test.html”的内容;我应该如何编辑 httpd.conf 以使其工作?

【问题讨论】:

  • 有什么提示吗?我做了几次尝试,但我都卡在了同一点上。

标签: apache centos7 httpd.conf


【解决方案1】:

这不是一个不同的站点,它是一个不同的目录。不同的站点将涉及不同的主机名。

由于您已经拥有DocumentRoot "/var/www/html/site1,并且您似乎不想创建新的虚拟主机,您可以使用Alias 指向一个新的/不同的目录

另外,您只希望 site2 在 /test/ 下加载 test.html 如果我在访问时理解正确,只需添加正确的 DirectoryIndex 指令即可。

这里是:

Alias /site2 /var/www/html/site2
<Directory /var/www/html/site2>
     DirectoryIndex /test/test.html
</Directory>

为此,您需要以下两个模块:

  • mod_alias
  • mod_dir(但你可能已经有了这个,因为你已经在使用 DirectoryIndex 指令了)

您也可以在 site1 下 mkdir site2,但这可能看起来更干净。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-31
    • 2015-08-26
    • 1970-01-01
    • 2012-05-17
    相关资源
    最近更新 更多