文档

Caddy Web Server 服务器的配置

If you are using a Caddy Web Server that does not support .htaccess rules, additional configuration is required for the Xilifox Image Optimizer plugin to work properly.

  • 步 1. #

    Start an SSH connection to your website or forward this instruction to your server administrator.

  • 步 2. #

    Go to the host configuration directory using the command:

    cd /etc/caddy

    Use the command to edit the configuration file:

    nano Caddyfile

  • 步 3. #

    In the configuration file, find the block responsible for your domain and add the following rules in it:

    # BEGIN XIO
    header /wp-content/*/*.jpg Cache-Control "private"
    header /wp-content/*/*.jpeg Cache-Control "private"
    header /wp-content/*/*.png Cache-Control "private"
    header /wp-content/*/*.webp Cache-Control "private"
     
    @acceptsAvif {
        header Accept *image/avif*
        path_regexp avif ^/wp-content/(.+)/(.+)\.(jpg|jpeg|png|webp)$
    }
    @acceptsWebp {
        header Accept *image/webp*
        path_regexp webp ^/wp-content/(.+)/(.+)\.(jpg|jpeg|png)$
    }
     
    handle @acceptsAvif {
        @hasAvif file /wp-content/uploads-xio/{re.avif.1}/{re.avif.2}.{re.avif.3}.avif
        rewrite @hasAvif /wp-content/uploads-xio/{re.avif.1}/{re.avif.2}.{re.avif.3}.avif
    }
    handle @acceptsWebp {
        @hasWebp file /wp-content/uploads-xio/{re.webp.1}/{re.webp.2}.{re.webp.3}.webp
        rewrite @hasWebp /wp-content/uploads-xio/{re.webp.1}/{re.webp.2}.{re.webp.3}.webp
    }
    # END XIO

    Please remember to:

    • add rules in the block responsible for your domain
    • if you have several blocks responsible for your domain (e.g. separate for HTTP and HTTPS), add rules in all blocks
    • add these rules before other directives in the block

  • 步 4. #

    Restart the Caddy server using the command:

    service caddy restart

  • 步 5. #

    就这样! Our plugin will work properly.

    If you encounter any problems, 请, 联系我们. We will try to help you.

不是您正在寻找的解决方案?

请检查其他 文章 或打开一个 工单.