Prestashop: gamification PNG Error on NGINX

Created on 6 Jan 2020  路  11Comments  路  Source: PrestaShop/PrestaShop

Hi we are moving all clients to NGINX, we follow all post on how to config the prestashop but we are getting only one error:

2020/01/06 22:00:09 [error] 8644#8644: *1 open() "/usr/share/nginx/html/xxxxx/admin/index.php/configure/advanced/modules/gamification/views/img/badges/42_0.png" failed (20: Not a directory), client: xxxx, server: xxxxxx, request: "GET /admin/index.php/configure/advanced/modules/gamification/views/img/badges/42_0.png HTTP/2.0", host: "xxxxxx", referrer: "https://xxxxx/admin/index.php/configure/advanced/performance/?_token=xxxx"

any idea?

thank you

1.7.5.2 1.7.6.2 BO Bug Gamification Trivial

Most helpful comment

Hi we think we have solve the issue doing this, please help us to confirm it:

find the file: modules\gamification\classes\Badge.php

line 51 and change

const BAGDE_IMG_URL = '../modules/gamification/views/img/badges/';

by

const BAGDE_IMG_URL = '/modules/gamification/views/img/badges/';

have a good day.

@msaustral @khouloudbelguith this works perfect for me 馃憤

All 11 comments

Hi @msaustral,

the issue is related to your server configuration.
This is a config file by default
https://github.com/PrestaShop/PrestaShop/blob/develop/docs/docker/nginx_fpm/prestashop-nginx/prestashop-nginx.conf
It is provided by PrestaShop & you should edit it to be compatible with your server.
For example, you should edit the root: https://github.com/PrestaShop/PrestaShop/blob/develop/docs/docker/nginx_fpm/prestashop-nginx/prestashop-nginx.conf#L5
You should edit the admin folder name
https://github.com/PrestaShop/PrestaShop/blob/develop/docs/docker/nginx_fpm/prestashop-nginx/prestashop-nginx.conf#L56

Thanks to check & feedback.

Hi thank you for your help, we did use that config file with all that modification, also we add some more, in fact everything works perfect the error is only with the Gamification module.

this is the config file:

server {
listen 80;
listen [::]:80;
server_name xxxxxxxx.xxxxx;
return 301 https://$server_name;
}

proxy_cache_path /tmp/cacheapi levels=1:2 keys_zone=microcacheapi:100m max_size=1g inactive=1d use_temp_path=off;

server {
# SSL Ipv4 & v6
listen 443 http2 default_server ssl ;
listen [::]:443 http2 default_server ssl ipv6only=on;

  access_log  /etc/nginx/logs/access.log;
  error_log  /etc/nginx/logs/error.log;

  ssl_session_cache shared:SSL:50m;
  ssl_session_timeout 1d;

  ssl_protocols TLSv1.2 TLSv1.3;
 #ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:RSA+3DES:AES128-SHA:!ADH:!AECDH:!MD5;
 ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
 #ssl_ciphers ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GC$;

  ssl_prefer_server_ciphers on;
# Enable session tickets
  ssl_session_tickets on;

# Your SSL Certificates, don't forget to take a look at Certbot (https://certbot.eff.org)
  ssl_certificate /etc/letsencrypt/live/xxxxxxxx.xxxxx/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/xxxxxxxx.xxxxx/privkey.pem;

# Do not forget to create this file before with OpenSSL : "openssl dhparam -out /opt/bitnami/letsencrypt/certificates/dhparam.pem 2048"
  ssl_dhparam /etc/nginx/ssl/dhparam.pem;


# OCSP Stapling
   ssl_stapling on;
   ssl_stapling_verify on;
   resolver 8.8.8.8 8.8.4.4 208.67.222.222 208.67.220.220 valid=60s;
   resolver_timeout 2s;

# [REQUIRED EDIT] Your domain name goes here
  server_name xxxxxxxx.xxxxx;

# [REQUIRED EDIT] Absolute path to your website root on the filesystem
root   /usr/share/nginx/html/xxxxx;
index index.php;

# Redirect 404 errors to prestashop
error_page 404 /index.php?controller=404;

server_tokens off;

location /api/ {

  # Micro caching
  proxy_cache microcacheapi;
  proxy_cache_valid 200 1s;
  proxy_cache_use_stale updating;
  proxy_cache_background_update on;
  proxy_cache_lock on;

}

# Gzip Settings, convert all types.
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 32 16k;
gzip_http_version 1.1;
gzip_min_length 250;

# Can be enhance to 5, but it can slow you server
# gzip_comp_level    5;
# gzip_min_length    256;



gzip_types
    application/atom+xml
    application/javascript
    application/json
    application/ld+json
    application/manifest+json
    application/rss+xml
    application/vnd.geo+json
    application/vnd.ms-fontobject
    application/x-font-ttf
    application/x-web-app-manifest+json
    application/xhtml+xml
    application/xml
    font/opentype
    image/bmp
    image/jpg
    image/png
    image/webp
    image/svg+xml
    image/x-icon
    text/cache-manifest
    text/css
    text/plain
    text/vcard
    text/vnd.rim.location.xloc
    text/vtt
    text/x-component
    text/x-cross-domain-policy;

# Brotli Settings
brotli on;
brotli_comp_level 4;
brotli_buffers 32 8k;
brotli_min_length 100;
brotli_static on;
brotli_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/jpg
image/png
image/webp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;

# HSTS (Force clients to interact with your website using HTTPS only)
# For enhanced security, register your site here: https://hstspreload.org/
# WARNING: Don't use this if your site is not fully on HTTPS!
# security headers
   add_header X-Frame-Options "SAMEORIGIN" always;
   add_header X-Cache-Status $upstream_cache_status;
   add_header X-XSS-Protection "1; mode=block" always;
   add_header X-Content-Type-Options "nosniff" always;
   add_header Referrer-Policy "no-referrer-when-downgrade" always;
   add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
   add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

location ~*  \.(jpg|jpeg|png|gif|ico|css|js|woff(?:2)?)$ {
    expires 365d;
}
location ~* \.(css|js)$ {
   expires 7d;
}

# Do not save logs for these
location = /favicon.ico {
    auth_basic off;
    allow all;
    log_not_found off;
    access_log off;
}

location = /robots.txt {
    auth_basic off;
    allow all;
    log_not_found off;
    access_log off;
}

# [REQUIRED EDIT IF MULTILANG]
# rewrite ^/fr$ /fr/ redirect;
# rewrite ^/fr/(.*) /$1;

# Images
rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$1$2$3.jpg last;
rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$1$2$3$4.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$5.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$6.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$7.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$8.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$9.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$10.jpg last;
rewrite ^/c/([0-9]+)(-[.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+.jpg$ /img/c/$1$2$3.jpg last;
rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+.jpg$ /img/c/$1$2.jpg last;

rewrite ^/[a-zA-Z][a-zA-Z]/index.php(.*)$ /index.php$1;
try_files $uri $uri/ /index.php?$args;

# Rewrites para controladores Symfony para prestashop 1.7

##Reemplazar adminxxxxxxxxx por la url de la administraci贸n de la tienda
location ~ /(international|_profiler|product|combination|specific-price)/(.*)$ {
    try_files $uri $uri/ /index.php?q=$uri&$args /xxxxxxxxxxx/index.php$is_args$args;
}

location /xxxxxxx/ {
    if (!-e $request_filename) {
        rewrite ^/.*$ /xxxxxxxx/index.php last;
    }
}

location / {
    try_files $uri $uri/ /index.php?$args;
    if (!-e $request_filename) {
        rewrite ^/.*$ /index.php last;
    }
}

# AlphaImageLoader for IE and fancybox
rewrite ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 last;

# Web service API
rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;

# File security
# .htaccess .DS_Store .htpasswd etc
location ~ /\. {
    deny all;
}
# Source code directories
location ~ ^/(app|bin|cache|classes|config|controllers|docs|localization|override|src|tests|tools|translations|travis-scripts|vendor|var)/ {
    deny all;
}
# Prevent exposing other sensitive files
location ~ \.(yml|log|tpl|twig|sass)$ {
    deny all;
}

# Prevent injection of php files
location /upload {
    location ~ \.php$ {
        deny all;
    }
}
location /img {
    location ~ \.php$ {
        deny all;
    }
}

# PHP FPM part
location ~ \.php$ {
    # Verify that the file exists, redirect to index if not
    #try_files $fastcgi_script_name /index.php$uri&$args =404;
    try_files $fastcgi_script_name /index.php$uri&$args;
    fastcgi_index  index.php;
    include       fastcgi_params;

    # Environment variables for PHP
    fastcgi_split_path_info ^(.+\.php)(/.+)$;


    fastcgi_param PATH_INFO       $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PHP_VALUE max_execution_time=180;

    # [REQUIRED EDIT] Connection to PHP-FPM - choose one
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

    fastcgi_keep_conn on;
    fastcgi_read_timeout 30s;
    fastcgi_send_timeout 30s;
    fastcgi_param  SERVER_PROTOCOL    HTTP/2.0;

    # In case of long loading or 502 / 504 errors
     fastcgi_buffer_size 256k;
     fastcgi_buffers 256 16k;
     fastcgi_busy_buffers_size 256k;
     client_max_body_size 10M;
}

}

@msaustral, thanks for these clarifications.
I have the same issue with PS1.7.6.2 & PS1.7.5.2 & the gamification module v2.3.2.
image

Issue reproduced with the Nginx server.
here's my configuration

server {
    listen   80; ## listen for ipv4; this line is default and implied
    listen   [::]:80 default ipv6only=on; ## listen for ipv6
        listen 443 ssl;

    root /var/www/html;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name prestashop.com;
        ssl_certificate /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key /etc/nginx/ssl/nginx.key;

    # Disable sendfile as per https://docs.vagrantup.com/v2/synced-folders/virtualbox.html
    sendfile off;

    # Add stdout logging
    # Add stdout logging
        error_log /var/log/nginx/error.log info;
        access_log /var/log/nginx/access.log;

        # Add option for x-forward-for (real ip when behind elb)
        #real_ip_header X-Forwarded-For;
        #set_real_ip_from 172.16.0.0/12;

    location /1762/ {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html
        try_files $uri $uri/ /1762/index.php?$args;
        # Images
                rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+2x.jpg$ /img/p/$1/$1$2$32x.jpg last;
                rewrite ^/1762/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$1$2$3.jpg last;
                rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+2x.jpg$ /img/p/$1/$2/$1$2$3$42x.jpg last;
                rewrite ^/1762/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last;
                rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+2x.jpg$ /img/p/$1/$2/$3/$1$2$3$4$52x.jpg last;
                rewrite ^/1762/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last;
                rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+2x.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$62x.jpg last;
                rewrite ^/1762/([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$6.jpg last;
                rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+2x.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$72x.jpg last;
                rewrite ^/1762/([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$7.jpg last;
                rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+2x.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$82x.jpg last;
                rewrite ^/1762/([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$8.jpg last;
                rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+2x.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$92x.jpg last;
                rewrite ^/1762/([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$9.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]+)?/.+2x.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$102x.jpg last;
                rewrite ^/1762/([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$10.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$10.jpg last;

                rewrite ^/1762/c/([0-9]+)(-[.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+.jpg$ /img/c/$1$2$3.jpg last;
                rewrite ^/1762/c/([a-zA-Z_-]+)(-[0-9]+)?/.+.jpg$ /img/c/$1$2.jpg last;
        # AlphaImageLoader for IE and fancybox
        rewrite ^images_ie/?([^/]+)\.(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 last;

        # Web service API
        rewrite ^/1762/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;

        # Installation sandbox
        rewrite ^(/1762/install(?:-dev)?/sandbox)/(.*) /$1/test.php last;
    }
    # Gzip Settings, convert all types.
        gzip on;
        gzip_vary on;
        gzip_proxied any;

        # Can be enhance to 5, but it can slow you server
        # gzip_comp_level    5;
        # gzip_min_length    256;

        gzip_types
            application/atom+xml
            application/javascript
            application/json
            application/ld+json
            application/manifest+json
            application/rss+xml
            application/vnd.geo+json
            application/vnd.ms-fontobject
            application/x-font-ttf
            application/x-web-app-manifest+json
            application/xhtml+xml
            application/xml
            font/opentype
            image/bmp
            image/svg+xml
            image/x-icon
            text/cache-manifest
            text/css
            text/plain
            text/vcard
            text/vnd.rim.location.xloc
            text/vtt
            text/x-component
            text/x-cross-domain-policy;

        gzip_disable "MSIE [1-6]\.(?!.*SV1)";
    # Symfony controllers
        location /1762/admin-dev/ {                                  # [REQUIRED EDIT] the name of your admin directory
            if (!-e $request_filename) {
                rewrite ^/.*$ /1762/admin-dev/index.php last;   # [REQUIRED EDIT] the name of your admin directory
            }
        }

        # Cloudflare / Max CDN fix
        location ~* \.(eot|otf|ttf|woff|woff2)$ {
            add_header Access-Control-Allow-Origin *;
        }

        # Do not save logs for these
        location = /1762/favicon.ico {
            log_not_found off;
            access_log off;
        }
        location = /1762/robots.txt {
            auth_basic off;
            allow all;
            log_not_found off;
            access_log off;
        }


    error_page 404 /1762/index.php?controller=404;

        location ^~ /sad.svg {
            alias /var/www/errors/sad.svg;
            access_log off;
        }
        location ^~ /twitter.svg {
            alias /var/www/errors/twitter.svg;
            access_log off;
        }
        location ^~ /gitlab.svg {
            alias /var/www/errors/gitlab.svg;
            access_log off;
        }

    # pass the PHP scripts to FastCGI server listening on socket
    #
    location ~ \.php$ {
                try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param SCRIPT_NAME $fastcgi_script_name;
        fastcgi_index index.php;
        include fastcgi_params;
    }

        location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|tiff|ttf|svg)$ {
                expires           5d;
        }

    # deny access to . files, for security
    #
    location ~ /\. {
            log_not_found off;
            deny all;
    }

    location ^~ /.well-known {
                allow all;
                auth_basic off;
        }

    # Source code directories
    location ~ ^/(app|bin|cache|classes|config|controllers|docs|localization|override|src|tests|tools|translations|travis-scripts|vendor|var)/ {
            deny all;
    }
    # Prevent injection of php files
        location /1762/upload {
            location ~ \.php$ {
                    deny all;
            }
        }
    location /1762/img {
            location ~ \.php$ {
                    deny all;
            }
        }

}

I鈥檒l add this to the debug roadmap so that it鈥檚 fixed. If you have already fixed it on your end or if you think you can do it, please do send us a pull request!
Thanks!

Hi we think we have solve the issue doing this, please help us to confirm it:

find the file: modules\gamification\classes\Badge.php

line 51 and change

const BAGDE_IMG_URL = '../modules/gamification/views/img/badges/';

by

const BAGDE_IMG_URL = '/modules/gamification/views/img/badges/';

have a good day.

Hi @msaustral,

Would you be willing to make a pull request on GitHub with your code suggestion?
https://github.com/PrestaShop/gamification
Thank you!

Hi we think we have solve the issue doing this, please help us to confirm it:

find the file: modules\gamification\classes\Badge.php

line 51 and change

const BAGDE_IMG_URL = '../modules/gamification/views/img/badges/';

by

const BAGDE_IMG_URL = '/modules/gamification/views/img/badges/';

have a good day.

@msaustral @khouloudbelguith this works perfect for me 馃憤

Hi @didi-2018, if you have already fixed it on your end, please do send us a pull request!
Thanks!

I do the PR 馃榿

@davidglezz can you please add 1.7.6.3?

@didi-2018 @msaustral try this:

const BAGDE_IMG_URL = _MODULE_DIR_ . 'gamification/views/img/badges/';

https://github.com/PrestaShop/gamification/pull/72/files

@didi-2018 @msaustral try this:

const BAGDE_IMG_URL = _MODULE_DIR_ . 'gamification/views/img/badges/';

https://github.com/PrestaShop/gamification/pull/72/files

@davidglezz is this better than this:
const BAGDE_IMG_URL = '/modules/gamification/views/img/badges/';

Was this page helpful?
0 / 5 - 0 ratings