Jump to content

nginx configuration for 1.7.1.2


Kfir Ozer

Recommended Posts

Hello.

it seems that Prestashop requires specific Nginx configuration since... I can't go to the products page in the admin url, it gives me 'page not found' because the url contains '/index.php/...' and there are no rewrite rules.

 

I googled and found Nginx configuration for PrestaShop 1.6 at http://doc.prestashop.com/display/PS16/System+Administrator+Guide but that blocked me from going to the admin page.

 

can anyone please specify proper nginx configuration for PrestaShop 1.7.1.2 ?

 

besides that.. this is the best e-commerce open source project with Hebrew support out of the box.

 

 

 

 

 

Link to comment
Share on other sites

This is what I use, and it works pretty well.  You'll need to change the /path/to/ps/ in that first location block

location /path/to/ps/ {
    index /path/to/ps/index.php;

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

# Directories explicitly allowed in directories blocked below
location ~ ^/(.*)/docs/csv_import/ {
    allow all;
}

# Block everything else in these directories
location ~ ^/(.*)/img/cms/ {
    deny all;
}

# Allow access to the ACME Challenge for Let's Encrypt
location ~ /\.well-known\/acme-challenge {
    allow all;
}

# Block all files with these extensions
location ~ \.(md|tpl)$ {
    deny all;
}

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

# 1 week expiry on CSS and JavaScript
location ~ \.(css|js)$ {
    expires 1w;
    add_header Cache-Control public;
    allow all;
}

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";                                             # Do people still use Internet Explorer 6? In that case, disable gzip and hope for the best!
gzip_vary on;                                                     # Also compress content with other MIME types than "text/html"
gzip_types application/json text/css application/javascript;      # We only want to compress json, css and js. Compressing images and such isn't worth it
gzip_proxied any;
gzip_comp_level 6;                                                # Set desired compression ratio, higher is better compression, but slower
gzip_buffers 16 8k;                                               # Gzip buffer size
gzip_http_version 1.0;                                            # Compress every type of HTTP request
Link to comment
Share on other sites

Hi.

Thank you for your response.

 

unfortunately this nginx configuration does not allow me to login into the admin page, it redirect me to the index.php file.

 

in my case the test domain is prestashop.tux-in.com and the root location is actually '/'.

 

this is my nginx configuration, please let me know what I need to change to make it work

server {
    listen 80;
    listen [::]:80;


    root /mnt/storage/html/prestashop;
    index index.php index.html index.htm index.nginx-debian.html;


    server_name prestashop.tux-in.com;


    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }




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;
}


# Directories explicitly allowed in directories blocked below
location ~ ^/(.*)/docs/csv_import/ {
    allow all;
}


# Block everything else in these directories
location ~ ^/(.*)/img/cms/ {
    deny all;
}


# Allow access to the ACME Challenge for Let's Encrypt
location ~ /\.well-known\/acme-challenge {
    allow all;
}


# Block all files with these extensions
location ~ \.(md|tpl)$ {
    deny all;
}


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


# 1 week expiry on CSS and JavaScript
location ~ \.(css|js)$ {
    expires 1w;
    add_header Cache-Control public;
    allow all;
}


##
# Gzip Settings
##


gzip on;
gzip_disable "msie6";                                             # Do people still use Internet Explorer 6? In that case, disable gzip and hope for the best!
gzip_vary on;                                                     # Also compress content with other MIME types than "text/html"
gzip_types application/json text/css application/javascript;      # We only want to compress json, css and js. Compressing images and such isn't worth it
gzip_proxied any;
gzip_comp_level 6;                                                # Set desired compression ratio, higher is better compression, but slower
gzip_buffers 16 8k;                                               # Gzip buffer size
gzip_http_version 1.0;                                            # Compress every type of HTTP request
}
Edited by Kfir Ozer (see edit history)
  • Like 1
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...