In Prestashop 1.7.5.1 + nginx, when I click in some pages inside backoffice it redirects to homepage. The problem appears with URLs with slashes like: /admin/index.php/sell/catalog/products/?_token=xxx or /admin/index.php/improve/international/localization/?_token=xxx
However, with URLs like: /admin/index.php?controller=AdminCategories&token=xxx or /admin/index.php?controller=AdminPsMboModule&token=xxx it works fine.
I have this configuration in nginx:
location /admin/ { # [REQUIRED EDIT] the name of your admin directory
if (!-e $request_filename) {
rewrite ^/.*$ /admin/index.php last; # [REQUIRED EDIT] the name of your admin directory
}
}
location / {
# Redirect pretty urls to index.php
try_files $uri $uri/ /index.php?$args;
# 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;
# 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;
# Installation sandbox
rewrite ^(/install(?:-dev)?/sandbox)/(.*) /$1/test.php last;
}
Additionnal information
PrestaShop version: 1.7.5.1
PHP version: 7.2
Hi @Krapulat,
I did not manage to reproduce the issue with PS1.7.5.1 & the Server software version: nginx/1.14.0 & PHP7.2.10.
I attached a video record.
https://drive.google.com/file/d/1d3RuM_6PeTT3_8ipsVCIn0eFoYF84CX-/view
here's my nginx configuration
server {
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default ipv6only=on; ## listen for ipv6
root /var/www/html;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name _;
# 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 / {
# First attempt to serve request as file, then
# as directory, then fall back to index.html
try_files $uri $uri/ /1750/index.php?$args;
# 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;
# 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;
# Installation sandbox
rewrite ^(/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 /1750/admin-dev/ { # [REQUIRED EDIT] the name of your admin directory
if (!-e $request_filename) {
rewrite ^/.*$ /1750/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 = /1750/favicon.ico {
log_not_found off;
access_log off;
}
location = /1750/robots.txt {
auth_basic off;
allow all;
log_not_found off;
access_log off;
}
error_page 404 /1750/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;
}
}
I created from this file https://github.com/PrestaShop/PrestaShop/blob/develop/docs/docker/nginx_fpm/prestashop-nginx/prestashop-nginx.conf
Thanks to check & feedback.
Hello @khouloudbelguith,
I've copied the nginx configuration server and it happens the same problem. I'm using varnish but I have this line to not cache the site:
if (req.http.host == "prestashop_site.com") {return (pipe);}
I've recorded a video to show the problem: https://drive.google.com/file/d/1ofqwZX9ym9zWuXu8g2-pdcJ8tzolw52V/view
@Krapulat, you have an issue with your configuration.
With symfony pages, you have redirection to the home page, thanks to follow this link for the correct redirection.
Thanks!
@khouloudbelguith I've tried this line but It doesn't work:
location /admin_dir/ { # [REQUIRED EDIT] the name of your admin directory
if (!-e $request_filename) {
rewrite ^/.*$ /admin_dir/index.php last; # [REQUIRED EDIT] the name of your admin directory
}
}
I also tried this one without luck:
location ~ /(international|_profiler|module|product|feature|attribute|supplier|combination|specific-price|configure)/(.*)$ {
try_files $uri $uri/ /index.php?q=$uri&$args /admin_dir/index.php$is_args$args;
}
I don't know where is the problem.
@Krapulat, it could be another problem, but I'm sure, it is on the config file.
We need to retrieve the PHP error log and the debug mode report in order to find out what's wrong.
Thanks!
@khouloudbelguith There is no error messages in php or nginx logs.
And with debug mode on, when I try to access to this admin pages I get:
[Debug] This page has moved
Please use the following URL instead: http://domain.com/index.php
@Krapulat, yes as I said, there is a redirection to the home page forced by your config.
Thanks!
@khouloudbelguith By "your config" do you mean nginx configuration? Or Prestashop configuration?
@Krapulat, no your nginx configuration.
In the file /etc/nginx/sites-available/default.conf you must write your own rules as we do for Apache. You must not use a rewrite where you don't need it.
More because it's an example and you can customize this part by everything you want.
Thanks!
@khouloudbelguith The same nginx configuration works fine with Prestashop 1.7.4.4 but not In Prestashop 1.7.5.1... I'll continue checking what's wrong.
@Krapulat, no, in my case in well working as described in my last screen-record.
Thanks!
Waiting for your feedback.
I'm also suffering the same problem.
Hi @dominictayloruk,
Here's the https://github.com/PrestaShop/PrestaShop/blob/develop/docs/docker/nginx_fpm/prestashop-nginx/prestashop-nginx.conf file you need to follow, you can customize this part by everything you want.
For my case, it is OK as described in this comment https://github.com/PrestaShop/PrestaShop/issues/12905#issuecomment-472744524
Thanks!
I'm running this docker image yobasystems/alpine-prestashop:latest
I've got the following block in the conf;
# Symfony controllers
location /admin/ {
if (!-e $request_filename) {
rewrite ^/.*$ /admin/index.php last;
}
}
as can be seen here; nginx conf
This directory gets renamed at container runtime to the environment variable to be the correct location e.g. /admin/ --> /adminXXXXXX/ , which can be confirmed by doing;
$cat /etc/nginx/nginx.conf
I get the errors on pages in the admin panel that are in folders rather than a query of index.php.
I've also tried adding the following;
location ~ /(_profiler|api|attribute|combination|configure|feature|improve|international|module|product|sell|specific-price|stock|supplier)/(.*)$ {
try_files $uri $uri/ /index.php?q=$uri&$args admin/index.php$is_args$args;
}
@dominictayloruk, if you enable debug mode, are there any exceptions displayed?
Thanks!
Yes i get the following exceptions
PHP message: PHP Fatal error: Uncaught Symfony\Component\Debug\Exception\UndefinedFunctionException: Attempted to call function "token_get_all" from namespace "Doctrine\Common\Annotations". in /usr/html/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php:56
21/03/2019 16:36:42Stack trace:
21/03/2019 16:36:42#0 /usr/html/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PhpParser.php(57): Doctrine\Common\Annotations\TokenParser->__construct('<?php namespace...')
21/03/2019 16:36:42#1 /usr/html/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php(415): Doctrine\Common\Annotations\PhpParser->parseClass(Object(ReflectionClass))
21/03/2019 16:36:42#2 /usr/html/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php(334): Doctrine\Common\Annotations\AnnotationReader->collectParsingMetadata(Object(ReflectionClass))
21/03/2019 16:36:42#3 /usr/html/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php(214): Doctrine\Common\Annotations\AnnotationReader->getClassImports(Object(ReflectionClass))
bash-4.4# php -v
PHP 7.2.14 (cli) (built: Jan 12 2019 20:59:08) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.14, Copyright (c) 1999-2018, by Zend Technologies
bash-4.4# nginx -v
nginx version: nginx/1.14.2
@dominictayloruk, in your server the extension is enbled tokenizer?
If you run php -m
on the command line, tokenizer is in the list?
Sorry, I just re-opened the issue.
Thanks to check & feedback.
No its not installed in the image, but there is a package available;
https://pkgs.alpinelinux.org/packages?name=php7*&branch=v3.9&arch=x86_64
apk update
apk add php7-tokenizer
And it is now working!!
I'll update the image yobasystems/alpine-prestashop with the added php7 module, so anyone wanting to run prestashop 1.7.4 with nginx and php 7.2 can use it. Its no where near as resource hungry as the official apache images.
@dominictayloruk, the issue is not a PrestaShop's core bug but most likely a server configuration.
I close the issue, feel free to open a new one when needed.
Thanks!
Use this code in your config file of your server
# Symfony controllers
location /admin/ { # [REQUIRED EDIT] the name of your admin directory
if (!-e $request_filename) {
rewrite ^/.*$ /admin/index.php last; # [REQUIRED EDIT] the name of your admin directory
}
}
Use this code in your config file of your server
Symfony controllers
location /admin/ { # [REQUIRED EDIT] the name of your admin directory if (!-e $request_filename) { rewrite ^/.*$ /admin/index.php last; # [REQUIRED EDIT] the name of your admin directory } }
This worked for me
Most helpful comment
Use this code in your config file of your server
# Symfony controllers
location /admin/ { # [REQUIRED EDIT] the name of your admin directory
if (!-e $request_filename) {
rewrite ^/.*$ /admin/index.php last; # [REQUIRED EDIT] the name of your admin directory
}
}