Support » Plugin: WebP Converter for Media » Nginx conf

  • Hello,

    I think nginx do not read .htaccess, so the webp image aren’t loaded.

    Would you please send the rewrite & cache block for nginx ?

    Thanks,

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

    (@mateuszgbiorczyk)

    Hi @moemos,

    Thank you very much for your message. Yes, I have settings to configure nginx.

    Please edit the configuration file:
    /etc/nginx/mime.types

    and add this code:

    types {
      # ...
    
      image/webp webp;
    }

    Then please find your configuration file in the path (default is default file):
    /etc/nginx/sites-available/

    and add below code in this file:

    server {
      # ...
    
      location ~ (?<root>.+)/uploads/(?<path>.+)\.(?<ext>jp?g|png|gif)$ {
        if ($http_accept !~* "image/webp") {
          break;
        }
        add_header Vary Accept;
        expires 365d;
        try_files $root/uploads-webpc/$path.$ext.webp $uri =404;
      }
    }

    Let me know if it works for you. I will be grateful for feedback!

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Hi @volatilparis,

    Hello, did you manage to solve your problem? Can I ask you for some comment on your case?

    The answer from you is very important to me so that my technical support can be improved.

    salmen2

    (@salmen2)

    Hello,
    Actually, I try to use the second code snippet and the images aren’t either in format image/webp or pointing to the uploads-webpc directory.

    Kind regards

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @salmen2, please see the FAQ of plugin for more information on your question. Read the How to check if plugin works? question in particular.

    I got it, thanks.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @salmen2, what is test result? Is everything working properly?

    Yes, I placed the code snippet above the W3 Total Cache configuration and cleared the cache. After a hard refresh of the site, the images are loading in the format webp.

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    Excellently @salmen2. Could I still help you somehow? Are you satisfied with the plugin’s operation?

    Yes, the plugin works as expected; no issues or problems to add

    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @salmen2, I am very pleased. Then maybe you could add a review? I will be very grateful!

    Added 🙂

    Hello. In this code i must put your code? y where?

    server {
    	server_name test.info www.test.info;
    	charset UTF-8;
    	index index.html index.php;
    	disable_symlinks if_not_owner from=$root_path;
    	include /etc/nginx/vhosts-includes/*.conf;
    	include /etc/nginx/vhosts-resources/test.info/*.conf;
    	access_log /var/www/httpd-logs/test.info.access.log;
    	error_log /var/www/httpd-logs/test.info.error.log notice;
    	set $root_path /var/www/test_user/data/www/test.info;
    	root $root_path;
        add_header Cache-Control private;
    location / {
        location ~ [^/]\.ph(p\d*|tml)$ {
          try_files /does_not_exists @php;
        }
    		location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
    			expires 90d;
    		}
    				        # Запрещаем доступ к .htaccess
            location ~ /\.ht {
                    deny all;
            }
            		location / {
    			try_files $uri $uri/ /index.php?$args; # permalinks
    		}
    }
    	location @php {
    		fastcgi_index index.php;
    		fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@test.info";
    		fastcgi_pass unix:/var/www/php-fpm/test_user.sock;
    		fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
    		try_files $uri =404;
    		include fastcgi_params;
    	}
    	ssi on;
    	gzip on;
    	gzip_comp_level 4;
    	gzip_disable "msie6";
    	gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
    	return 301 https://test.info$request_uri;
    	listen 95.183.10.97:80;
    }
    server {
    	server_name test.info www.test.info;
    	ssl_certificate "/var/www/httpd-cert/test_user/test.info_le1.crtca";
    	ssl_certificate_key "/var/www/httpd-cert/test_user/test.info_le1.key";
    	ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
    	ssl_prefer_server_ciphers on;
    	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    	add_header Strict-Transport-Security "max-age=31536000;";
    	ssl_dhparam /etc/ssl/certs/dhparam4096.pem;
    	charset UTF-8;
    	index index.html index.php;
    	disable_symlinks if_not_owner from=$root_path;
    	include /etc/nginx/vhosts-includes/*.conf;
    	include /etc/nginx/vhosts-resources/test.info/*.conf;
    	access_log /var/www/httpd-logs/test.info.access.log;
    	error_log /var/www/httpd-logs/test.info.error.log notice;
    	ssi on;
    	set $root_path /var/www/test_user/data/www/test.info;
    	root $root_path;
    	listen 95.183.10.97:443 ssl;
    	gzip on;
    	gzip_comp_level 4;
    	gzip_disable "msie6";
    	gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
    	location / {
    		location ~ [^/]\.ph(p\d*|tml)$ {
    			try_files /does_not_exists @php;
    		}
    		location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
    			expires 90d;
    		}
    				location / {
    			try_files $uri $uri/ /index.php?$args; # permalinks
    		}
    	}
    	location @php {
    		fastcgi_index index.php;
    		fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@test.info";
    		fastcgi_pass unix:/var/www/php-fpm/test_user.sock;
    		fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
    		try_files $uri =404;
    		include fastcgi_params;
    	}
    }
    Plugin Author Mateusz Gbiorczyk

    (@mateuszgbiorczyk)

    @alex5237, This is a support forum for the plugin. We do not solve server configuration problems here.

    You have the implementation example above. Match it for your server – everyone is different. I can’t help everyone in such a detailed way.

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.