1

我正在尝试在 Apache2 Web 服务器上设置过期 HTTP 加热器,但我所做的每一次尝试都没有效果或使网站崩溃。我尝试将 expires 标头设置添加到我VirtualHost的,如下所示,但这会使网站崩溃。我不明白这是为什么?

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /home/mydirectory
    <Directory /home/mydirectory/>
            ExpiresActive On
            ExpiresByType text/html "access plus 1 months"
            ExpiresByType image/gif "access plus 1 months"
            ExpiresByType image/jpg "access plus 1 months"
            ExpiresByType image/jpeg "access plus 1 months"
            ExpiresByType image/png "access plus 1 months"
            ExpiresByType image/vnd.microsoft.icon "access plus 1 months"
            ExpiresByType image/x-icon "access plus 1 months"
            ExpiresByType image/ico "access plus 1 months"
            ExpiresByType application/javascript .now plus 1 months.
            ExpiresByType application/x-javascript .now plus 1 months.
            ExpiresByType text/javascript .now plus 1 months.
            ExpiresByType text/css .now plus 1 months.
            ExpiresDefault "access plus 1 days
    </Directory>
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            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 ${APACHE_LOG_DIR}/error.log

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

    CustomLog ${APACHE_LOG_DIR}/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>

</VirtualHost>

我已经为我的 httpd.conf 文件尝试了以下两种配置:

LoadModule expires_module /usr/lib/apache2/modules/mod_expires.so

ExpiresActive On
ExpiresDefault "access plus 7 days"

<Directory "/home/mydirectory">
    Options FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
    ExpiresByType text/html "access plus 1 day"
    ExpiresByType text/css "access plus 1 day"
    ExpiresByType text/javascript "access plus 1 day"
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 day"
</Directory>

 LoadModule expires_module /usr/lib/apache2/modules/mod_expires.so

我无法获得任何适合我的配置组合。我检查了 mod_expires.so 是否在正确的位置。我哪里错了?

我已将文档根目录从 更改/var/www/home/mydirectory. 在我尝试修改 HTTP 标头之前,这并没有造成任何问题,所以我认为这与问题没有任何关系。

4

2 回答 2

0
ExpiresDefault "access plus 1 days

on the 19th line is missing an " which maybe make your configuration corrupt?

于 2013-07-02T12:11:33.053 回答
0

I had a similar problem that was solved by changing the word "one" with the numeral "1". "one" had worked on another site of mine. Perhaps it would work to change the numeral into a word.

于 2013-06-25T20:11:32.240 回答