Jump to content

Nginx/PHP7 image generation


Recommended Posts

Hello,

i've been using an import plugin that imports the CSV data do the catalog (products) along with the images.

Local installation (Vagrant - Apache/PHP 5.6) works just fine even if i dont do "Regenerate thumbnails" - when there is no generated image for a product it generates the image in the right folder.

But on a staging/production server i will be using Nginx/PHP7, so i want the same behaviour since im importing large amount of products (around 20k) and it takes a lot of time to generate so many images/thumbnails. I want to only import images, and when needed (i.e when product is being viewed in the backend or in frontend) the image is generated.

This is the behaviour i managed to do on Apache, but Nginx seems to have some problem with that behaviour, since it does not generate images when requested, it just throws 404 error on GET request.

 

This is my nginx configuration:

server {
    listen      ip.here:80;
    server_name domain.com www.domain.com;
    root        /home/useraccount/web/domain.com/public_html;
    index       index.php index.html;
    access_log  /var/log/nginx/domains/domain.com.log combined;
    access_log  /var/log/nginx/domains/domain.com.bytes bytes;
    error_log   /var/log/nginx/domains/domain.com.error.log error;

    location = /favicon.ico {
        log_not_found off;      # PrestaShop by default does not provide a favicon.ico
        access_log off;         # Disable logging to prevent excessive log sizes
    }


     location = /robots.txt {
         auth_basic off;        # Whatever happens, always let bots know about your policy
         allow all;
         log_not_found off;     # Prevent excessive log size
         access_log off;
    }

    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }


    location / {
	index /index.php;

        rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
        rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2.jpg last;
        rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$1$2$3$4.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8.jpg last;
        rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
        rewrite ^/c/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
        rewrite ^/c/([a-zA-Z-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1.jpg last;
        rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg last;
	    try_files $uri $uri/ /index.php?$args;

#        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
#            expires     max;
#        }

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    127.0.0.1:9004;
            fastcgi_index   index.php;
	        fastcgi_read_timeout 14400;
            proxy_read_timeout 14400;
	        include         /etc/nginx/fastcgi_params;
        }
    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   /home/useraccount/web/domain.com/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    include     /home/useraccount/conf/web/nginx.domain.com.conf*;
}

Have anyone had a problem like this and how to solve it? Thanks in advance.

 

 

Best regards.

Edited by [email protected] (see edit history)
Link to comment
Share on other sites

  • 1 month later...

To all whom it may concern - this is confirmed bug for prestashop on full nginx setup.

Problem is that when the ImageManager requests the image for resize, it gets 404 and thus it doesnt create any new images.

How was this confirmed?  Is the issue reported to their forge?  What version of PS are effected?

Link to comment
Share on other sites

Version 1.6.1.10 affected.

I think that it was reported on their forge long time ago (i have spoken to a ex-presta core developer and he have confirmed this bug to me) but not fixed yet.

So are you saying this is an issue with Prestashop, or with your customization? 

 

I just tested adding a new product, and then adding a new image to the product, and the thumbnails were created properly, and I did not receive a 404 error page.

 

Also Prestashop does not have functionality to generate thumbnails on demand, so I assume you or your developer has created this customization, and perhaps they did it incorrectly. 

 

So are you sure this is a defect with Prestashop?  Or is this really a defect with your customization?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...