There is two issue with NGINX configurations.
I tried to setup prestashop on CentOS 7 with Nginx according to this instrument that I found similar this in Prestashop forums . the nginx.config file is as below:

    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    events {
        worker_connections 1024;
http {
  client_header_timeout 300;
  client_body_timeout 300;
  fastcgi_read_timeout 300;
  client_max_body_size 32m;
  fastcgi_buffers 8 128k;
  fastcgi_buffer_size 128k;
  map $http_upgrade $connection_upgrade {
      default upgrade;
      ''      close;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   6500;
    types_hash_max_size 3048;
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    include /etc/nginx/conf.d/*.conf;
    include nginx-prestashop.conf;

and nginx-prestashop.conf file is:

upstream php-fpm {
    server; #unix:/run/php-fpm/www.sock;
server {
    root /var/www/html/prestashop;
    index  index.php index.html index.htm;
    server_name example.com www.example.com;
    server_name_in_redirect off;
    error_log /var/log/nginx/error.log;
    location / {
    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 ~ \.php$ {
    try_files  $uri =404;
    fastcgi_index            index.php;
    fastcgi_pass             php-fpm;
    include                  fastcgi_params;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;
    fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
server {
  server_name example.com www.example.com;
  server_tokens off; 
  error_log /var/log/nginx/error.log;
  server_name_in_redirect off;
  ssl on;
  ssl_certificate /etc/nginx/sslnginx.crt;
  ssl_certificate_key /etc/nginx/sslnginx.key;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_prefer_server_ciphers on;
  ssl_session_cache shared:SSL:10m;
  ssl_session_timeout 5m;
  location / {
     proxy_redirect $scheme://$host:443/;
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection $connection_upgrade;
 location ~ /\.ht {
     deny all;

when I tried http://www.example.com it redirects me to localhost/index.phph? and when I tried https://www.example.com/ it took me to NGINX default page which locates in /usr/share/nginx/html/ and when I tried insight of server, I encountered Connection refused message.
I removed default configs.
I could not find the reason.

  • The second problem is because it looks like you want to proxy_pass from the https server to the http server, but you have forgotten to add the proxy_pass directive. IDK why you are getting redirected to localhost - is prestashop configured that way? – Richard Smith Oct 14 '18 at 19:59
  • @RichardSmith, I edit my question.next, could you provide me code of your mentioned, because I test many codes and unfortunately I'm not familiar with nginx – Hossein Vatani Oct 15 '18 at 2:17
  • Remove the try_files. IIRC there's a bug that prevents php-fpm to work correctly. – Gerard H. Pille Oct 15 '18 at 9:37
  • @GerardH.Pille,this not worked – Hossein Vatani Oct 22 '18 at 18:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.