简体   繁体   中英

Enable favicon on Apache 2.4 with SSL

I have Django app and can serve favicon via it. But it is not recommended so I did it using Apache.

Previously I had HTTP 80 configs. After moving from HTTP to SSL 443 I cannot access the favicon on the server anymore.

The part of responsible config looks like:

<VirtualHost *:443>

        DocumentRoot /home/ubuntu/project/project/

        Alias /favicon.ico /home/ubuntu/project/static/favicon.ico
        Alias /static/ /home/ubuntu/project/static/

        <Location />
           Require host mysite.com
        </Location>

        <Directory /home/ubuntu/project/static>
            Require all granted
        </Directory>
    </VirtualHost>

Folder exists and favicon is located in it.

When I am trying to access favicon.ico I get 403:

Forbidden
You don't have permission to access /favicon.ico on this server.

How can I solve it?

Updates:

  1. I have found here that ServerAliases are ignored with SSL, so probably Aliases are ignored as well.

  2. Here is good overview How to serve favicons with Django, but I want to do it only with Apache to minimize the number of requests to Django.

  3. Here some developers suggested me to check favicon permissions but it didn't help.

  4. The problem is in the root location directive which restricts access to the whole website. If somebody knows how to make exception just for favicon please post it in answer!

My solution was to remove:

    <Location />
       Require host mysite.com
    </Location>

and instead use:

    <Directory  /home/ubuntu/project/project>
       Require host mysite.com
    </Directory>

It helped to serve the favicon, but I still don't like it because I have removed the check of host on root url. Any other solutions are welcome!

参数中指定的路径不是 URL 的一部分,而是为您的应用提供服务的文件系统的一部分。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM