• Resolved ironman199xx

    (@ironman199xx)


    Hello,

    Sorry to bother you, but I have installed your plugin to convert images to WebP on two sites. However, it seems that the images have been successfully converted to WebP format in the gallery. But when I check them in the browser, following the instructions, the images still appear in their old size and JPEG format. I believe this issue might be related to Nginx, and I have attempted to configure it for a while without success.

    Here is my Nginx configuration file, which is running in a Docker container at /etc/nginx/conf.d/default.conf.

    # nginx.vh.default.conf  --  docker-openresty
    #
    # This file is installed to:
    #   /etc/nginx/conf.d/default.conf
    #
    # It tracks the server section of the upstream OpenResty's nginx.conf.
    #
    # This config (and any other configs in etc/nginx/conf.d/) is loaded by
    # default by the include directive in /usr/local/openresty/nginx/conf/nginx.conf.
    #
    # See https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files
    #
    
    events {
        # Configure events here
    }
    
    http {
    
      server {
    # 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
        listen       80;
        server_name  mydomain.com;
    
        #charset koi8-r;
        #access_log  /var/log/nginx/host.access.log  main;
    
        location / {
            root   /usr/local/openresty/nginx/html;
            index  index.html index.htm;
        }
    
        #error_page  404              /404.html;
    
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/openresty/nginx/html;
        }
    
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   https://127.0.0.1;
        #}
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           /usr/local/openresty/nginx/html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
            deny  all;
    
       }
    }

    Please review and suggest any necessary corrections or modifications. Thank you.

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

    (@mateuszgbiorczyk)

    Hi @ironman199xx,

    Thank you for your message.

    I made a video showing how to configure Nginx. Please check them out. The reason why it doesn’t work for you is probably related to the file where you added new rules.

    Best, Mateusz

    Thread Starter ironman199xx

    (@ironman199xx)

    Thanks for your answer, but I have tried configuring according to your video instructions many times, and the configuration can’t seem to pass nginx’s syntax check. Please provide me with more solutions to solve this problem. I have worked hard for 2 weeks to convert images to webp, but it seems that my nginx configuration is not correct. I know your plugin is very good because I have used many image conversion plugins before, and I believe you can help me solve my problem. I configured the site on a VPS using EasyEngine, and nginx runs in a Docker container.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @ironman199xx In the first message you sent the contents of the default.conf file. For my Nginx server, I had an individual Nginx configuration file for each site. Maybe this is the source of the problem?

    Thread Starter ironman199xx

    (@ironman199xx)

    Good morning! To have a better understanding of how my Nginx server works, please take a minute to read this Nginx configuration guide: https://github.com/openresty/docker-openresty/blob/master/README.md#nginx-config-files.

    If you would like to have direct access to my server to help solve my issue, I can provide you with the server’s IP and root account details. Just send me an email, and I will share my account information with you through that.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @ironman199xx I cannot access your server. This is against the WordPress forum rules. I can only help you here on the forum and my help is based on my experience. I tested many Nginx servers and had no similar problems. What I can do is try to help you theoretically – we must respect the rules of this support forum.

    In my opinion you added the rules in the wrong file. Please see what my configuration file looks like:

    server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;
    
        server_name demo.mattplugins.com;
    
        client_max_body_size 64M;
    
        access_log /home/domains/demo.mattplugins.com/logs/access.log;
        error_log /home/domains/demo.mattplugins.com/logs/error.log;
    
        error_page 404 /index.php;
    
        index index.php index.html index.htm;
        root /home/domains/demo.mattplugins.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_param PHP_VALUE open_basedir="/tmp:/home/domains/demo.mattplugins.com/public_html";
            fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
        }
    }
    
    server {
        if ($host = demo.mattplugins.com) {
            return 301 https://$host$request_uri;
        }
    
        listen 80;
        listen [::]:80;
    
        server_name demo.mattplugins.com;
    
        return 301 https://demo.mattplugins.com$request_uri;
    }

    This file is located in the following location:
    /etc/nginx/sites-available/demo.mattplugins.com

    I have an idea for a little test. Please add these rules in the Nginx configuration instead of the ones you have (I added a test header there):

    # 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 "";
    }
    
    add_header Test-header "OK!";
    
    location ~ /wp-content/(?<path>.+)\.(?<ext>jpe?g|png|gif|webp)$ {
        add_header Test-header-img "OK!";
        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

    After adding these rules, please give me the URL to your site. I will check if the test headers are visible on the page.

    Thread Starter ironman199xx

    (@ironman199xx)


    Thank you very much. Finally, after many days of trying, I have successfully converted the images to webp using your plugin. My nginx configuration file is located at /usr/local/openresty/nginx/conf/conf.d/main.conf, and here is its full content after being configured according to your instructions.

    # Add your custom config in custom/user.conf
    # ALL CHANGES IN THIS FILE WILL BE LOST AFTER EasyEngine Update
    
    upstream php {
    	server mydomain.com_php:9000;
    }
    
    
    server {
    
    	access_log   /var/log/nginx/access.log;
    	error_log    /var/log/nginx/error.log;
    
    	root /var/www/htdocs;
    
    	server_name mydomain.com;
    
    	index index.php index.html index.htm;
    # 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
    
    
    
    	# PHP NGINX CONFIGURATION
    	location / {
    		try_files $uri $uri/ /index.php?$args;
    	}
    	location ~ \.php$ {
    		try_files $uri =404;
    		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    		include fastcgi_params;
    		fastcgi_pass php;
    	}
    
    	# WordPress COMMON SETTINGS
    	# Limit access to avoid brute force attack
    	location = /wp-login.php {
    		limit_req zone=one burst=1 nodelay;
    		include fastcgi_params;
    		fastcgi_pass php;
    	}
    	# Disable wp-config.txt
    	location = /wp-config.txt {
    		deny all;
    		access_log off;
    		log_not_found off;
    	}
    	# Disallow php in upload folder
    	location /wp-content/uploads/ {
    		location ~ \.php$ {
    			#Prevent Direct Access Of PHP Files From Web Browsers
    			deny all;
    		}
    	}
    
    	# NGINX CONFIGURATION FOR COMMON LOCATION
    	# Basic locations files
    	location = /favicon.ico {
    		access_log off;
    		log_not_found off;
    		expires max;
    	}
    
    	location = /robots.txt {
    	# Some WordPress plugin gererate robots.txt file
    	# Refer #340 issue
    		try_files $uri $uri/ /index.php?$args;
    		access_log off;
    		log_not_found off;
    	}
    	# Cache static files
    	location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|woff2|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|swf)$ {
    		add_header "Access-Control-Allow-Origin" "*";
    		access_log off;
    		log_not_found off;
    		expires max;
    	}
    	# Security settings for better privacy
    	# Allow LetsEncrypt HTTP challenge URL
    	location ^~ /.well-known/acme-challenge/ {
    		auth_basic off;
    		allow all;
    		try_files $uri =404;
    		break;
    	}
    	# Deny hidden files
    	location ~ /\. {
    		deny all;
    		access_log off;
    		log_not_found off;
    	}
    
    	# Deny backup extensions & log files
    	location ~* ^.+\.(bak|log|old|orig|original|php#|php~|php_bak|save|swo|swp|sql)$ {
    		deny all;
    		access_log off;
    		log_not_found off;
    	}
    	# Return 403 forbidden for readme.(txt|html) or license.(txt|html) or example.(txt|html)
    	if ($uri ~* "^.+(readme|license|example)\.(txt|html)$") {
    		return 403;
    	}
    	# Status pages
    	location = /ee-admin/nginx_status {
    		stub_status on;
    		access_log off;
    	}
    	location = /ee-admin/status {
    		include fastcgi_params;
    		fastcgi_pass php;
    	}
    	location = /ee-admin/ping {
    		include fastcgi_params;
    		fastcgi_pass php;
    	}
    	location ~*  \.(css|js)$ {
    		access_log off;
    		expires 1d;
    		add_header Cache-Control "public, must-revalidate";
    	}
    
    
    	client_max_body_size 100m;
    
    	include /usr/local/openresty/nginx/conf/custom/*.conf;
    }

    I hope it will be helpful for others, like me, who are working with your plugin. Thank you once again.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘nginx config not available and Error code: rewrites_not_executed’ is closed to new replies.