Jump to content

Nginx server trouble: Friendly URLs redirecting to server index page


Recommended Posts

So everything is running smoothly until I enable the Friendly URLs option under "SEO & URLs". After enabling the option and loading the shop front, all of the URLs have been replaced with the shortened URLs as expected.If I attempt to load any of the shortened URLS beyond the root shop directory (such as clicking on a product or category), I am served with the default nginx index page (i.e. the index page from the server root directory). With Friendly URLs disabled, the shop works fine.

 

Prestashop is running from a sub directory on the nginx server "/shop/" and I have created a vhost to point to it. My current configuration includes Ubuntu Server 13.04, with Nginx, php5, php-fpm, varnish (port 80), and memcache. I have also added the nginx comptiable rewrite rules to the vhost file as other threads have suggested.

 

Any suggestions?

 

vhost files:

 

default:

server {
	listen 8080;
	listen [::]:8080 default_server ipv6only=on;
	root /usr/share/nginx/html;
	index index.php index.html index.htm;
	# Make site accessible from http://localhost/
	server_name localhost;

	location / {
			# First attempt to serve request as file, then
			# as directory, then fall back to displaying a 404.
			try_files $uri $uri/ /index.html;
			# Uncomment to enable naxsi on this location
			# include /etc/nginx/naxsi.rules
	}
	location /doc/ {
			alias /usr/share/doc/;
			autoindex on;
			allow 127.0.0.1;
			allow ::1;
			deny all;
	}


	error_page 404 /404.html;

	error_page 500 502 503 504 /50x.html;
	location = /50x.html {
			root /usr/share/nginx/html;
	}
	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	#
	location ~ \.php$ {
	#	   fastcgi_split_path_info ^(.+\.php)(/.+)$;
	#	   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
	#
	#	   # With php5-cgi alone:
	#	   fastcgi_pass 127.0.0.1:9000;
	#	   # With php5-fpm:
			fastcgi_pass unix:/var/run/php5-fpm.sock;
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			include fastcgi_params;
	}
}

 

shop.vhost:

server {
   listen 7080;
   server_name localhost;
   root /usr/share/nginx/html/shop;
 if ($http_host != "localhost") {
		   rewrite ^ http://localhost/shop/$request_uri permanent;
}
   index index.php index.html;
   location = /favicon.ico {
			log_not_found off;
			access_log off;
   }
   location = /robots.txt {
			allow all;
			log_not_found off;
			access_log off;
   }
   # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
   location ~ /\. {
			deny all;
			access_log off;
			log_not_found off;
   }

rewrite_log on;
	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$
	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/$
	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$
	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/$$
	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 "^/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 ^/contacts$ /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;
   try_files $uri $uri/ /index.php$is_args$args;
   error_page 404 /index.php?controller=404;
   location ~* \.(gif)$ {
	  expires 2592000s;
   }
   location ~* \.(jpeg|jpg)$ {
	  expires 2592000s;
   }
   location ~* \.(png)$ {
	  expires 2592000s;
   }
   location ~* \.(css)$ {
	  expires 604800s;
   }
   location ~* \.(js|jsonp)$ {
	  expires 604800s;
   }
   location ~* \.(js)$ {
	  expires 604800s;
   }
   location ~* \.(ico)$ {
	  expires 31536000s;
   }
   location ~ \.php$ {
 location ~ \.php$ {
			try_files $uri =404;
			include /etc/nginx/fastcgi_params;
			fastcgi_pass unix:/var/run/php5-fpm.sock;
			fastcgi_index index.php;
			fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
			fastcgi_intercept_errors on;
   }
}

Edited by zn7 (see edit history)
Link to comment
Share on other sites

  • 6 months later...

Hello,

 

After some hours trying to run all images under our prestashop from a costumer, we solve it as simple as:

 

 

## visit www.mandanwebs.com support and programming of prestashop

location /store {

## www.mandanwebs.com




## www.mandanwebs.com
               try_files $uri $uri/ /store/index.php?$args;
               ##error_page 404 /index.php?controller=404;
}
rewrite ^/store/([0-9]+)\-([0-9]+)(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /store/img/p/$1-$2$3.jpg ;

 

 

I hope help someone we work on it some hours.

  • Like 1
Link to comment
Share on other sites

  • 6 months later...

Thanks mate for the head up,

your indeed saved me a lot a time

 

i changed mine like below since i moved the store to a sub-domain:

location /shop {
		index index.php;

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

All working good now  :)

Link to comment
Share on other sites

  • 5 months later...

Thanks mate for the head up,

your indeed saved me a lot a time

 

i changed mine like below since i moved the store to a sub-domain:

location /shop {
		index index.php;

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

All working good now  :)

I don't see product images with this settings, are you sure they 100% work ?

Link to comment
Share on other sites

  • 9 months later...
×
×
  • Create New...