Jump to content

Nginx prestashop 1.6.1.9 and 1.7 not working


RickD1

Recommended Posts

 Hello ,

 
I want to install and use prestashop in nginx. It is way easier to get it working on apache, but because of 
security conserns we do prefer nginx.
 
I have not a lot of experience with nginx nor prestashop so i am not fully understanding what i am doing. 
 
I created rewrite rules in the nginx config and i sucessfully installed prestashop. But i do encounter serious 
problems which might be very hard to fix or not.
 
When i installed prestashop 1.7 everything was working fine. But when i clicked on modules & services 
i would be redirected to the root of the server ( which is because it probably is a 404 error ). The other option for modules does work. 
 
I tried several different configurations and ended up installing prestashop 1.6.9.6. Again everything is working even the modules & services. So i installed a plug-in i needed. And when i connected to the front office the same thing happens as in 1.7 at the modules & services. While in 1.7 the front office did function normally.
 
I have no clue where to find what is going wrong. I assume it has something to do with the rewrite rules. 
 
 
 
I have installed prestashop in a separate folder in the web-server root, because i am just testing. And it should not interfere with the website running at the moment. 
 
So i have for example : www.example.com and www.example.com/prestashop. Maybe the configuration assumes that the files inside /prestashop  should be in the root. But that would be weird because it is working but some things do not. 
 
 
I hope someone can take some time to help me. I have no clue what to do and i am pretty frustrated since i want to make this working very badly. 
 
I will give some specifics about the server:
I am using php5-fpm 
 
Also i will enclose some information about the nginx configuration. 
 
 
root@localhost:/etc/nginx/shopapps.d# cat prestashop.conf 
 charset utf-8;
    client_max_body_size 200M;
 
 
    ######################################################
    ##  MultiSite Support
    ##   WORLD SITES
    ##  For Google optimization reasons, this customer has a .co.uk domain for UK customers
    ##  and a .com for global visitors
    ##  the .com url will be in the following format:
    ##  NOTE:  This is a multisite url NOT a prestashop language URL
    ##  www.myshop.com/us   (USA)
    ##  www.myshop.com/fr   (France)
    ##  www.myshop.com/ca   (canada)
    ##  etc.  These URLs are then registered as country specific in Google Webmaster Tools.
    ##  NEXT:  if  multilingual is also required
    ##  the url format is:
    ##  www.myshop.com/ca/fr
    ##  www.myshop.com/ca/en
    ##  etc.
    #######################################################
    ##  only rewrite for a given domain
    ##  this could be moved to the server definition file instead of here...
    ##  however I have placed it here to save having two different
    ##  server definitions
    ##  
    if ($http_host ~ "^www.example.com/prestashop/$") {
        rewrite '^/([a-zA-Z]{2})$'     /$1/ redirect;
        rewrite '^/([a-zA-Z]{2})/(.*)'     /$2;
    }
 
    rewrite ^/api$ /api/ last;
    ##  ALL IMAGES REWRITE
    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-]*)/[_a-zA-Z0-9-]*.jpg$   /img/c/$1$2.jpg last;
    rewrite ^/c/([a-zA-Z-]+)/[a-zA-Z0-9-]+.jpg$                 /img/c/$1.jpg last;
    rewrite ^/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$     /img/c/$1$2.jpg last;
 
    rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$              /js/jquery/plugins/fancybox/images/$1.$2 last;
 
 
    rewrite '^/order/step([0-9]).html$'      /index.php?controller=order&step=$2   last;
    rewrite '^/quick-order$'                 /index.php?controller=order-opc       last;
    rewrite '^/password-recovery$'           /index.php?controller=password        last;
 
 
    if (!-e $request_filename){
        rewrite ^(.*)$ /index.php?q=$1 last;
    }
 
    location /api { 
        rewrite ^/api/(.*)$ /webservice/dispatcher.php?url=$1 break; 
    }
 
    # Do not log robots.txt or favicon.ico file requests
    location ~* ^/(favicon.ico|robots.txt)$ {
        access_log off;
        log_not_found off;
    }
 
    # Custom Prestashop 404 page
    error_page 404 /index.php?controller=404;
 
    #  Set long expirey values for CSS and Images (assuming you dont change them too often)
    location ~* ^.+.(gif|jpg|jpeg|png|wmv|avi|mpg|mpeg|mp4|htm|html|js|css|mp3|swf|ico|flv|xml) {
        access_log off;
        expires 30d;
    }
 
 
 
root@localhost:/etc/nginx/shopapps.d# cat php.conf 
# location ~ \.php$ {
 #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#        fastcgi_pass unix:/var/run/php5-fpm.sock;
#        fastcgi_index    index.php;
#        fastcgi_read_timeout 7200;  # 2 hours for big cron jobs...
#        include fastcgi_params;
#    }
 
 
 
        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
fastcgi_read_timeout 300;
        }
 
 
location = /robots.txt  { allow all; access_log off; log_not_found off; }
    location = /favicon.ico { access_log off; log_not_found off; }      
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~ /\.          { deny all; }
    location ~ ~$           { access_log off; log_not_found off; deny all; }
    location = /CVS         { deny all;}
 
    location ~ (\.inc\.php|\.tpl|\.sql|\.tpl\.php|\.db)$ { deny all; }
    location ~ /\.ht { deny all; }
 
    # Deny access to any files with a .php extension in the uploads directory
    # Works in sub-directory installs and also in multisite network
    # Keep logging the requests to parse later (or to pass to firewall utilities such as fail2ban)
    location ~* /(?:uploads|files)/.*\.php$ {
        deny all;
    }
    location ~ ^/(README|INSTALL|LICENSE|CHANGELOG|UPGRADING)$ {
        deny all;
    }
    location ~ ^/(bin|SQL)/ {
        deny all;
    }
 
 
 
root@localhost:/etc/nginx/sites-available# cat www.example.conf 
## we only  want one access method into this store so rewrite myshop.com to www.myshop.com
    server { 
        listen         80; 
        server_name     _;     
        rewrite ^ http://www.example.com/prestashop/$request_uri? permanent; 
    }
    server {
        listen        80;
        server_name     _;
 
        server_name_in_redirect off;
 
        root            /var/www/somesite/prestashop/;
        index           index.php index.htm index.html  ;
        access_log      /var/log/nginx/access.myshop.co.uk.log;
        error_log       /var/log/nginx/error.myshop.co.uk.log debug;
 
        ##  Now include our shared config files
        include         shopapps.d/prestashop.conf;
        include         shopapps.d/drop.conf;
        include         shopapps.d/php.conf;
    }
 
 
If you need more information or different information please let me know.
 
I am very greatful for help !! 
 
Link to comment
Share on other sites

It has been some time since i posted this thread. There were 80 views on the time of writing.

Is this question to hard or do people not want to answer ?

 

Is it possible for someone to paste an nginx configuration that does work on their systems , maybe we can figure out 

the differences.

 

I am very greatfull for help !!! 

Link to comment
Share on other sites

  • 2 weeks later...

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...