apache Location 确实比 Directory 慢

apache Location 确实比 Directory 慢

在我的 apache 服务器上,我有一个 https 虚拟主机配置如下:

<VirtualHost *:443>
        ServerName www.example.com
        DocumentRoot /var/www/localhost/htdocs
    CustomLog /var/log/apache2/access_log combined
        ErrorLog /var/log/apache2/error_log
        ScriptAlias /cgi-bin/ /var/www/localhost/cgi-bin/
        <Directory "/var/www/localhost/cgi-bin">
                AllowOverride None
                Options None
                Require all granted
        </Directory>
Include /etc/apache2/vhosts.d/include_bdd_access
        <Directory "/var/www/localhost/htdocs">
                Options -Indexes +MultiViews
                AllowOverride All
                DirectoryIndex index.html index.php
                <LimitExcept HEAD POST GET>
                        Require all denied
                </LimitExcept>
                Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
                Header always append X-Frame-Options SAMEORIGIN
                Header set X-XSS-Protection "1; mode=block"
                Header set X-Content-Type-Options nosniff 
                AuthName "Global auth"
                Include /etc/apache2/vhosts.d/include_bdd_auth
        </Directory>
        <Location /webalizer>
                Options +Indexes -MultiViews -FollowSymLinks
        </Location>
[...]
SSLCertificateFile /etc/letsencrypt/live/www.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

webalizer/ 仅列出了 10 个目录,例如:

site1.example.com
site2.example.com
...

一切都很好,除了访问 /webalizer 目录确实非常慢(每次正好 16 秒,不多不少,由 Firefox Web 工具确认)而且我不明白为什么。

我意识到如果我将 Location 指令更改为 Directory,则“仅”需要大约 2 秒。

但是,我有其他相同的选项+索引,只需大约 8 秒即可显示 4 行...

这些子目录的内容有啥联系吗?

为什么使用目录比使用位置快得多?

那么,如果可能的话,是否建议使用目录呢?

还有一件事我不明白:

我可以参观www.example.com和:

$ curl https://username:[email protected]

但是,无法访问 /webalizer(使用位置或目录)

$ curl 'https://username:[email protected]/webalizer'
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://www.example.com/webalizer/">here</a>.</p>

为什么?

VirtualHost configuration:
*:80                   is a NameVirtualHost
         default server www.example.com (/etc/apache2/vhosts.d/www.example.com-le-ssl.conf:1)
[...]
ServerRoot: "/usr/lib64/apache2"
Main DocumentRoot: "/usr/htdocs"
Main ErrorLog: "/var/log/apache2/error_log"
Mutex ssl-stapling: using_defaults
Mutex authn-socache: using_defaults
Mutex ssl-cache: dir="/run/apache_ssl_mutex" mechanism=fcntl 
Mutex default: dir="/var/run/" mechanism=default 
Mutex mpm-accept: using_defaults
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
PidFile: "/run/apache2.pid"
Define: PHP
Define: AUTH_MYSQL
Define: LANGUAGE
Define: SSL
Define: STATUS
Define: SUEXEC
Define: MPM_ITK
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=72
Group: name="apache" id=72

相关内容