Jump to content

Problemas con Urls Amigables en NGINX


tderma

Recommended Posts

Tengo un problema con las url en el servidor que tengo estan configurado 2 paginas 

En raiz esta worpdres, y en /tienda/ una tienda

 

No consigo que prestashop funcione. eh usado lo siguiente configuracion pero no me a funcionado y algunas variantes...

# This is a default site configuration which will simply return 404, preventing

# chance access to any other virtualhost.

server {
        
listen 80 default_server;

        
listen [::]:80 default_server;
	
server_name  kch.enelsrv.com;
        
root /html/;

        

location / {
		
	#index  index.html index.php index.htm ;
		
	#try_files $uri $uri/ /index.php?$args;
        	
	try_files $uri $uri/ /index.php$uri&$args;
        	
	index index.php index.html index.htm;
        
	}

        

# You may need this to prevent return 404 recursion.
        
location = /404.html {
                
	internal;
        
	}

        

location ~ \.php$ {
              
	fastcgi_pass      php-fpm:9000;
              
	fastcgi_index     index.php;
              
	include           fastcgi.conf;
        
	}

}




server {
        l
listen 443 default_server;

        
listen [::]:442 default_server;
	
server_name kch.enelsrv.com;
        
root /html/;
        
ssl on;
        
ssl_certificate /etc/nginx/certs/cert.pem;
        
ssl_certificate_key /etc/nginx/certs/privkey.pem;
        
ssl_session_timeout 5m;

	
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        
ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-CAMELLIA256-SHA:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-SEED-SHA:DHE-RSA-CAMELLIA128-SHA:HIGH:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS';
        
ssl_prefer_server_ciphers on;


        

# You may need this to prevent return 404 recursion.
        
location = /404.html {
                
internal;
        
}



    

location / {
	
index  index.html index.php index.htm ;
	
try_files $uri $uri/ /index.php?$args;
       
# index index.html index.php; 
## Allow a static html file to be shown first
        
expires 30d; 
## Assume all files are cachable
 
 
       
}

  


# Index de Prestashop
location /tienda/{
      
index /tienda/index.php;
      

expires 30d; 

# Media: images, icons, video, audio, HTC
rewrite ^/tienda/api/?(.*)$ /tienda/webservice/dispatcher.php?url=$1 last;
rewrite ^/tienda/([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /tienda/img/p/$1/$1$2.jpg last;
rewrite ^/tienda/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /tienda/img/p/$1/$2/$1$2$3.jpg last;
rewrite ^/tienda/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /tienda/img/p/$1/$2/$3/$1$2$3$4.jpg last;
rewrite ^/tienda/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /tienda/img/p/$1/$2/$3/$4/$1$2$3$4$5.jpg last;
rewrite ^/tienda/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /tienda/img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6.jpg last;
rewrite ^/tienda/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /tienda/img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7.jpg last;
rewrite ^/tienda/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /tienda/img/p/$1/$2/$3/$4/$5/$6  /$7/$1$2$3$4$5$6$7$8.jpg last;
rewrite ^/tienda/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?/[_a-zA-Z0-9-]*.jpg$ /tienda/img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
rewrite ^/tienda/c/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /tienda/img/c/$1$2.jpg last;
rewrite ^/tienda/c/([a-zA-Z-]+)/[a-zA-Z0-9-]+.jpg$ /tienda/img/c/$1.jpg last;
rewrite ^/tienda/([0-9]+)(-[_a-zA-Z0-9-]*)/[_a-zA-Z0-9-]*.jpg$ /tienda/img/c/$1$2.jpg last;


# Personalizadas 1
rewrite "^/tienda/([0-9]+)\-(\P{M}\p{M}*)+\.html(.*)$" /tienda/index.php?controller=product&id_product=$1$3 last;
 
rewrite "^/tienda/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /tienda/index.php?controller=category&id_category=$1$3 last;
 
rewrite "^/tienda/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$" /tienda/index.php?controller=product&id_product=$2$4 last;
 
rewrite "^/tienda/([0-9]+)__([a-zA-Z0-9-]*)(.*)$" /tienda/index.php?controller=supplier&id_supplier=$1$3 last;
 
rewrite "^/tienda/([0-9]+)_([a-zA-Z0-9-]*)(.*)$" /tienda/index.php?controller=manufacturer&id_manufacturer=$1$3 last;
 
rewrite "^/tienda/content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /tienda/index.php?controller=cms&id_cms=$1$3 last;
 
rewrite "^/tienda/content/category/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /tienda/index.php?controller=cms&id_cms_category=$1$3 last;
 
rewrite "^/tienda/module/([_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)$" /tienda/index.php?fc=module&module=$1&controller=$2 last;
 


# Url de Prueba
rewrite "^/tienda/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /tienda/index.php?id_category=$8$4controller=category last;

# Personalizadas Sistema
rewrite ^/tienda/page-not-found$ /tienda/index.php?controller=404 last;
 
rewrite ^/tienda/address$ /tienda/index.php?controller=address last;
 
rewrite ^/tienda/addresses$ /tienda/index.php?controller=addresses last;
 
rewrite ^/tienda/authentication$ /tienda/index.php?controller=authentication last;
 
rewrite ^/tienda/best-sales$ /tienda/index.php?controller=best-sales last;
 
rewrite ^/tienda/cart$ /tienda/index.php?controller=cart last;
 
rewrite ^/tienda/contact-us$ /tienda/index.php?controller=contact-form last;
 
rewrite ^/tienda/discount$ /tienda/index.php?controller=discount last;
 
rewrite ^/tienda/guest-tracking$ /tienda/index.php?controller=guest-tracking last;
 
rewrite ^/tienda/order-history$ /tienda/index.php?controller=history last;
 
rewrite ^/tienda/identity$ /tienda/index.php?controller=identity last;
 
rewrite ^/tienda/manufacturers$ /tienda/index.php?controller=manufacturer last;
 
rewrite ^/tienda/my-account$ /tienda/index.php?controller=my-account last;
 
rewrite ^/tienda/new-products$ /tienda/index.php?controller=new-products last;
 
rewrite ^/tienda/order$ /tienda/index.php?controller=order last;
 
rewrite ^/tienda/order-follow$ /tienda/index.php?controller=order-follow last;
 
rewrite ^/tienda/quick-order$ /tienda/index.php?controller=order-opc last;
 
rewrite ^/tienda/order-slip$ /tienda/index.php?controller=order-slip last;
 
rewrite ^/tienda/password-recovery$ /tienda/index.php?controller=password last;
 
rewrite ^/tienda/prices-drop$ /tienda/index.php?controller=prices-drop last;
 
rewrite ^/tienda/search$ /tienda/index.php?controller=search last;
 
rewrite ^/tienda/sitemap$ /tienda/index.php?controller=sitemap last;
 
rewrite ^/tienda/stores$ /tienda/index.php?controller=stores last;
 
rewrite ^/tienda/supplier$ /tienda/index.php?controller=supplier last;

 
try_files $uri $uri/ /tienda/index.php?$args;   
}
 
    

location  /. { 

## Disable .htaccess and other hidden files
        
return 404;
    
}
 
    

location @handler { 
## Common front handler
        
rewrite / /index.php;
    

}
 

    
location ~ .php/ { 
## Forward paths like /js/index.php/x.js to relevant handler
        
rewrite ^(.*.php)/ $1 last;
    
}
 
    

location ~ .php$ { 
## Execute PHP scripts
        
if (!-e $request_filename) { 
        	
rewrite / /index.php last; ## Catch 404s that try_files miss
    
}
 

        

location ~ \.php$ {
              
expires 		off;
              
fastcgi_pass      php-fpm:9000;
              
fastcgi_index     index.php;
              
include           fastcgi.conf;
             

# fastcgi_param  
HTTPS $fastcgi_https;
              
fastcgi_param  
SCRIPT_FILENAME  
$document_root$fastcgi_script_name;
              
proxy_read_timeout 600s;
              
fastcgi_read_timeout 600;

        
}

}

}

 

En este momento solo tengo esta.

# This is a default site configuration which will simply return 404, preventing
# chance access to any other virtualhost.
server {
        listen 80 default_server;

        listen [::]:80 default_server;
	server_name  kch.enelsrv.com;
        root /html/;

        location / {
		#index  index.html index.php index.htm ;
		#try_files $uri $uri/ /index.php?$args;
        	try_files $uri $uri/ /index.php$uri&$args;
        	index index.php index.html index.htm;
        }

        # You may need this to prevent return 404 recursion.
        location = /404.html {
                internal;
        }

        location ~ \.php$ {
              fastcgi_pass      php-fpm:9000;
              fastcgi_index     index.php;
              include           fastcgi.conf;
        }
}


server {
        listen 443 default_server;

        listen [::]:442 default_server;
	server_name kch.enelsrv.com;
        root /html/;
        ssl on;
        ssl_certificate /etc/nginx/certs/cert.pem;
        ssl_certificate_key /etc/nginx/certs/privkey.pem;
        ssl_session_timeout 5m;

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-CAMELLIA256-SHA:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-SEED-SHA:DHE-RSA-CAMELLIA128-SHA:HIGH:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS';
        ssl_prefer_server_ciphers on;


        # You may need this to prevent return 404 recursion.
        location = /404.html {
                internal;
        }



    location / {
	index  index.html index.php index.htm ;
	try_files $uri $uri/ /index.php?$args;
       # index index.html index.php; ## Allow a static html file to be shown first
        expires 30d; ## Assume all files are cachable
 
        }

   location /tienda/{
      index index.php;
      expires 30d; ## Assume all files are cachable
rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
 
rewrite "^/c/([0-9]+)(\-[_a-zA-Z0-9-]*)/(.*)\.jpg$" /img/c/$1$2.jpg last;
 rewrite "^/c/([_a-zA-Z-]+)/(.*)\.jpg$" /img/c/$1.jpg last;
 
rewrite "^/([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/(\P{M}\p{M}*)*\.jpg$" /img/p/$1-$2$3.jpg last;
 rewrite "^/([0-9]+)\-([0-9]+)/(\P{M}\p{M}*)*\.jpg$" /img/p/$1-$2.jpg last;
 rewrite "^/([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$1$2.jpg last;
 rewrite "^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$1$2$3.jpg last;
 rewrite "^/([0-9])([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?/(\P{M}\p{M}*)*\.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-]*)?/(\P{M}\p{M}*)*\.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-]*)?/(\P{M}\p{M}*)*\.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-]*)?/(\P{M}\p{M}*)*\.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-]*)?/(\P{M}\p{M}*)*\.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-]*)?/(\P{M}\p{M}*)*\.jpg$" /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9.jpg last;
 
rewrite "^/([0-9]+)\-(\P{M}\p{M}*)+\.html(.*)$" /index.php?controller=product&id_product=$1$3 last;
 rewrite "^/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=category&id_category=$1$3 last;
 rewrite "^/([a-zA-Z0-9-]*)/([0-9]+)\-([a-zA-Z0-9-]*)\.html(.*)$" /index.php?controller=product&id_product=$2$4 last;
 rewrite "^/([0-9]+)__([a-zA-Z0-9-]*)(.*)$" /index.php?controller=supplier&id_supplier=$1$3 last;
 rewrite "^/([0-9]+)_([a-zA-Z0-9-]*)(.*)$" /index.php?controller=manufacturer&id_manufacturer=$1$3 last;
 rewrite "^/content/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=cms&id_cms=$1$3 last;
 rewrite "^/content/category/([0-9]+)\-([a-zA-Z0-9-]*)(.*)$" /index.php?controller=cms&id_cms_category=$1$3 last;
 rewrite "^/module/([_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)$" /index.php?fc=module&module=$1&controller=$2 last;
 
rewrite ^/page-not-found$ /index.php?controller=404 last;
 rewrite ^/address$ /index.php?controller=address last;
 rewrite ^/addresses$ /index.php?controller=addresses last;
 rewrite ^/authentication$ /index.php?controller=authentication last;
 rewrite ^/best-sales$ /index.php?controller=best-sales last;
 rewrite ^/cart$ /index.php?controller=cart last;
 rewrite ^/contact-us$ /index.php?controller=contact-form last;
 rewrite ^/discount$ /index.php?controller=discount last;
 rewrite ^/guest-tracking$ /index.php?controller=guest-tracking last;
 rewrite ^/order-history$ /index.php?controller=history last;
 rewrite ^/identity$ /index.php?controller=identity last;
 rewrite ^/manufacturers$ /index.php?controller=manufacturer last;
 rewrite ^/my-account$ /index.php?controller=my-account last;
 rewrite ^/new-products$ /index.php?controller=new-products last;
 rewrite ^/order$ /index.php?controller=order last;
 rewrite ^/order-follow$ /index.php?controller=order-follow last;
 rewrite ^/quick-order$ /index.php?controller=order-opc last;
 rewrite ^/order-slip$ /index.php?controller=order-slip last;
 rewrite ^/password-recovery$ /index.php?controller=password last;
 rewrite ^/prices-drop$ /index.php?controller=prices-drop last;
 rewrite ^/search$ /index.php?controller=search last;
 rewrite ^/sitemap$ /index.php?controller=sitemap last;
 rewrite ^/stores$ /index.php?controller=stores last;
 rewrite ^/supplier$ /index.php?controller=supplier last;

    }
 
    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }
 
    location @handler { ## Common front handler
        rewrite / /index.php;
    }
 
    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*.php)/ $1 last;
    }
 
    location ~ .php$ { ## Execute PHP scripts
        if (!-e $request_filename) { 
        	rewrite / /index.php last; ## Catch 404s that try_files miss
    }
 

        location ~ \.php$ {
              expires 		off;
              fastcgi_pass      php-fpm:9000;
              fastcgi_index     index.php;
              include           fastcgi.conf;
             # fastcgi_param  HTTPS $fastcgi_https;
              fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
              proxy_read_timeout 600s;
              fastcgi_read_timeout 600;

        }
}
}

 

Link to comment
Share on other sites

  • 10 months later...

Buenas tardes;

Tengo el mismo problema que tu, tengo configurado prestashop en Plesk con Nginx, y he leido que no es compatible con los .htaccess. 

He seguido la doc oficial para reescribir las reglas de nginx en el fichero de configuracion del host virtual. 

http://doc.prestashop.com/display/PS16/System+Administrator+Guide#SystemAdministratorGuide-NginxfriendlyURLs

Pero aunque lo configure correctamente, me sigue mostrando un 404 not found, a pesar de que si accedo por url al index.php y desactivo las urls amigables, el enlace si que entra en la tienda. 

Alguien podría indicar si lo ha conseguido solucionar o que hay que hacer exactamente para que funcione esto? He visto un montón de paginas por internet pero ninguna termina de especificar el problema del todo para su solución. 

Gracias anticipado. 

Saludos. 

Link to comment
Share on other sites

Actualizo: He conseguido dejar funcionando las urls amigables con Apache, cambiando la directiva en Plesk.

Pero estaría bien alguna sugerencia de como configurar Nginx para esas cosas. 

Saludos. 

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