• Resolved happyfanyiming

    (@happyfanyiming)


    Can you tell me in detail how to modify these codes to my configuration? My server is Nginx

    
    
    Follow the 4 steps below (please do all of them):
    Step 1
    
    Find the configuration file in one of the paths (remember to select configuration file used by your vhost):
    – /etc/nginx/sites-available/ or /etc/nginx/sites-enabled/
    – /etc/nginx/conf.d/
    
    and add this code (add these lines at the beginning of the server { … } block) – remember to add these rules before any other location {} rules:
    
    BEGIN Converter for Media
    
    set $ext_avif ".avif";
    if ($http_accept !~* "image/avif") {
    set $ext_avif "";
    }
    
    set $ext_webp ".webp";
    if ($http_accept !~* "image/webp") {
    set $ext_webp "";
    }
    
    location ~ /wp-content/(?.+).(?jpe?g|png|gif|webp)$ {
    add_header Vary Accept;
    expires 365d;
    try_files
    /wp-content/uploads-webpc/$path.$ext$ext_avif
    /wp-content/uploads-webpc/$path.$ext$ext_webp
    $uri =404;
    }
    
    END Converter for Media
    
    Step 2
    
    Then add support for the required MIME types, if they are not supported. Edit the configuration file:
    – /etc/nginx/mime.types
    
    and add this code (add these lines inside the types { … } block):
    
    image/webp webp;
    image/avif avif;

    下面的是我的Nginx配置文件:

    user  www www;
    worker_processes auto;
    error_log  /www/wwwlogs/nginx_error.log  crit;
    pid        /www/server/nginx/logs/nginx.pid;
    worker_rlimit_nofile 51200;
    
    stream {
        log_format tcp_format '$time_local|$remote_addr|$protocol|$status|$bytes_sent|$bytes_received|$session_time|$upstream_addr|$upstream_bytes_sent|$upstream_bytes_received|$upstream_connect_time';
      
        access_log /www/wwwlogs/tcp-access.log tcp_format;
        error_log /www/wwwlogs/tcp-error.log;
        include /www/server/panel/vhost/nginx/tcp/*.conf;
    }
    
    events
        {
            use epoll;
            worker_connections 51200;
            multi_accept on;
        }
    
    http
        {
            include       mime.types;
    		#include luawaf.conf;
    
    		include proxy.conf;
    
            default_type  application/octet-stream;
    
            server_names_hash_bucket_size 512;
            client_header_buffer_size 32k;
            large_client_header_buffers 4 32k;
            client_max_body_size 50m;
    
            sendfile   on;
            tcp_nopush on;
    
            keepalive_timeout 60;
    
            tcp_nodelay on;
    
            fastcgi_connect_timeout 300;
            fastcgi_send_timeout 300;
            fastcgi_read_timeout 300;
            fastcgi_buffer_size 64k;
            fastcgi_buffers 4 64k;
            fastcgi_busy_buffers_size 128k;
            fastcgi_temp_file_write_size 256k;
    		fastcgi_intercept_errors on;
    
            gzip on;
            gzip_min_length  1k;
            gzip_buffers     4 16k;
            gzip_http_version 1.1;
            gzip_comp_level 2;
            gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
            gzip_vary on;
            gzip_proxied   expired no-cache no-store private auth;
            gzip_disable   "MSIE [1-6]\.";
    
            limit_conn_zone $binary_remote_addr zone=perip:10m;
    		limit_conn_zone $server_name zone=perserver:10m;
    
            server_tokens off;
            access_log off;
    
    server
        {
            listen 888;
            server_name phpmyadmin;
            index index.html index.htm index.php;
            root  /www/server/phpmyadmin;
                location ~ /tmp/ {
                    return 403;
                }
    
            #error_page   404   /404.html;
            include enable-php.conf;
        # BEGIN Converter for Media
    set $ext_avif ".avif";
    if ($http_accept !~* "image/avif") {
        set $ext_avif "";
    }
    
    set $ext_webp ".webp";
    if ($http_accept !~* "image/webp") {
        set $ext_webp "";
    }
    
    location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif|webp)$ {
        add_header Vary Accept;
        expires 365d;
        try_files
            /wp-content/uploads-webpc/$path.$ext$ext_avif
            /wp-content/uploads-webpc/$path.$ext$ext_webp
            $uri =404;
    }
    # END Converter for Media
            location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
            {
                expires      30d;
            }
    
            location ~ .*\.(js|css)?$
            {
                expires      12h;
            }
    
            location ~ /\.
            {
                deny all;
            }
    
            access_log  /www/wwwlogs/access.log;
        }
    include /www/server/panel/vhost/nginx/*.conf;
    }
    
    

    我不会传图片,所以请见谅

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @happyfanyiming,

    Thank you for your message. I am sorry you have encountered a problem with our plugin. Do not worry, I will try to help you.

    I want to see what might have gone wrong. Could you send me a screenshot of the Help Center tab in the plugin’s settings? I will check it because in this tab I have information about the status of your website.

    Best,
    Mateusz

    Thread Starter happyfanyiming

    (@happyfanyiming)

    https://i.postimg.cc/4NVq6rZg/aaaaaaaaaaaaaaa.png

    https://i.postimg.cc/6qGLXJz5/bbbbbbbbbbbb.png

    https://i.postimg.cc/x9rSXPYQ/bbbbbbbbbbbb.jpg

    我不太会传图片 麻烦您点击下链接查看图片吧 谢谢了

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Thank you for your answer @happyfanyiming,

    Probably the Nginx configuration was not done correctly. I once prepared a video showing the configuration of the Nginx server (it is a pure Nginx server installed on Linux):
    https://www.youtube.com/watch?v=2er6He-Pl_U

    Unfortunately, despite my best intentions, I cannot be responsible for configuring the plugin user’s server. Why this video was created to show that the configuration described in the plugin’s FAQ is correct.

    Thread Starter happyfanyiming

    (@happyfanyiming)

    好的 谢谢回复我,我会查看你的视频。@mateuszgbiorczyk

    Thread Starter happyfanyiming

    (@happyfanyiming)

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @happyfanyiming I checked what you show in the screenshots and it means you are not adding it in the correct place.

    Below is an example host configuration file from the Nginx server (your configuration file will be different, but look for similarities). Read it to better understand where you should add the rules (described above) for our plugin in your configuration file.

    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
    
        server_name your-domain.com;
    
        client_max_body_size 32M;
    
        access_log /home/your-domain.com/logs/access.log;
        error_log /home/your-domain.com/logs/error.log;
    
        error_page 404 /index.php;
    
        index index.php index.html;
        root /home/your-domain.com/public_html;
    
        # BEGIN Converter for Media
        set $ext_avif ".avif";
        if ($http_accept !~* "image/avif") {
            set $ext_avif "";
        }
    
        set $ext_webp ".webp";
        if ($http_accept !~* "image/webp") {
            set $ext_webp "";
        }
    
        location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif|webp)$ {
            add_header Vary Accept;
            expires 365d;
            try_files
                /wp-content/uploads-webpc/$path.$ext$ext_avif
                /wp-content/uploads-webpc/$path.$ext$ext_webp
                $uri =404;
        }
        # END Converter for Media
    
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
    
        location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        }
    
        ...
    }
    Thread Starter happyfanyiming

    (@happyfanyiming)

    谢谢你的回复,可能是我太笨了,还是没有成功,我把我的操作放在了youtube 您看看是不是我操作错误

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @happyfanyiming Thank you for preparing the video.

    I think this is the wrong file where you pasted these rules. I saw there server_name as phpmyadmin and so it’s not your website’s on rules. Look for a file where your domain will be located.

    Thread Starter happyfanyiming

    (@happyfanyiming)

    你是对的,太对了,我的确是修改了错误的配置文件,修改这个文件就能使用你的插件了:-/www/server/panel/vhost/nginx/www.yinfazu.net.conf

    现在正在使用中,希望能让我的网站快一点

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @happyfanyiming I’m glad you were able to set it up. Thank you for your confirmation.

    If you want to achieve the best results, I recommend trying the AVIF format – then the images will be even smaller.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Changed the config but still doesn’t work [Converter for Media’ is closed to new replies.