Jump to content

Using NGINX with Ps 1.6 - what to pay attention to?


Recommended Posts

Hello,

 

I am considering switching to NGINX for my PS 1.6 installation, and am wondering what I need to pay attention to, besides the friendly URL's instructions as specified here: http://doc.prestashop.com/display/PS16/System+Administrator+Guide#SystemAdministratorGuide-NginxfriendlyURLs

 

For example, there are a couple of Apache specific instructions in the BO, like performance / apache optimization, or SEO/URL disable multiviews / disable mod_security

 

Should I leave these alone, do they still play a role in NGINX?

 

And are there other settings / changes that are required with NGINX?

 

Thanks for your input and help!

 

Dan

Link to comment
Share on other sites

Rewrite rules are different on Nginx.
 

  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 ^/order$ /index.php?controller=order last;
  if (!-e $request_filename){
    rewrite ^(.*)$ /index.php last;
  }

Tested and working with PS 1.6.0.9 & nginx 1.6.0 server

  • Like 1
Link to comment
Share on other sites

The Apache-specific settings in Prestashop do not matter at all if you're using Nginx. All these settings do is to change how Prestashop writes the .htaccess file, and .htaccess files are completely ignored by Nginx anyway.

 

Below is the interesting part of the Nginx config we're currently using for Prestashop 1.6.0.9 with friendly URLs enabled. It's basically a translation of all the .htaccess files into Nginx config syntax.

 

A couple of things you might need to adjust:

1) The config assumes you rename admin to admin666 and install to install666 after the initial Prestashop install. Just edit the line with the 666 in it if you did another rename.

2) The socket name in fastcgi_pass.

# Needed by the installer
location = /install/sandbox/anything.php {
	rewrite .* /install/sandbox/test.php last;
}

# Pass API requests to the webservice dispatcher
location ^~ /api/ {
	rewrite ^/api/(.*) /webservice/dispatcher.php?url=$1 last;
}

# Block all files starting with ., like .htaccess
location ~ /\. {
	deny all;
}

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

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

# Block everything else in these directories
location ~ ^/(admin666/backups|admin666/export|admin666/import|admin666/tabs|classes|config|docs|download|install666|localization|log|override|tools|translations)/ {
	deny all;
}

# 1 month expiry on other static stuff
# Also do the friendly URL rewrites
location ~* \.(eot|gif|ico|jpg|jpeg|otf|pdf|png|svg|swf|ttf|woff)$ {
	rewrite ^/([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$1$2$3.jpg break;
	rewrite ^/([0-9])([0-9])(\-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+\.jpg$ /img/p/$1/$2/$1$2$3$4.jpg break;
	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 break;
	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 break;
	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 break;
	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 break;
	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 break;
	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 break;
	rewrite ^/c/([0-9]+)(\-[\.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2$3.jpg break;
	rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+\.jpg$ /img/c/$1$2.jpg break;
	rewrite ^/images_ie/?([^/]+)\.(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 break;
	# next line is PSCSX-2790 bug workaround, fixed in 1.6.0.10
	rewrite ^/[a-zA-Z]+/img/cms/(.*)$ /img/cms/$1 break;
	expires 1M;
	add_header Cache-Control public;
	allow all;
}

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

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

# PHP
location ~ \.php$ {
	try_files $uri =404;
	fastcgi_buffer_size  128k;
	fastcgi_buffers      4 256k;
	fastcgi_pass         unix:/var/run/php-fpm/www.sock;
	fastcgi_read_timeout 180;
	fastcgi_param        HTTP_MOD_REWRITE On;
	include              fastcgi.conf;
}

# The rest is either served directly or passed on to the dispatcher
location / {
	try_files $uri $uri/ /index.php?$args;
}

  • Like 5
Link to comment
Share on other sites

Hi everyone, thanks for your input and recommendations, I really appreciate.

 

How about other BO settings, like disable apache multiviews, disable mod_security and apache optimization - I assume those BO settings are no longer functional in Nginx and are completely ignored by the sever?

 

Is there anything else I need to know about Nginx vs Apache?

Link to comment
Share on other sites

Hi everyone, thanks for your input and recommendations, I really appreciate.

 

How about other BO settings, like disable apache multiviews, disable mod_security and apache optimization - I assume those BO settings are no longer functional in Nginx and are completely ignored by the sever?

 

Is there anything else I need to know about Nginx vs Apache?

 

Like I wrote above, the BO settings related to Apache are completely ignored by Nginx, so just ignore them.

 

My config subset above should include all the Prestashop-specific stuff. It of course needs to be included into your basic Nginx config, typically inside a server section.

Link to comment
Share on other sites

  • 1 month later...

Why don't you use nginx over apache? This way you don't have to tweak anything, the auto generated htaccess files work, etc.

 

Have you seens any benchmarks on a sucha set up ?

I am really qurious to check if working with 2 webservers does actually boost load time or not

Link to comment
Share on other sites

I am on Myhosting.com and I recently bought an Apache Optimization package from them for my VPS - one of the things they did was to install NGINX as reverse proxy, so like rampage.rado said, it's using Nginx over Apache.

 

Personally, I think it's a really snappy solution, the default template with optimized images and 8 products for New / Popular / Best Sellers as well as slider and banners active, it all loads in 2-3 seconds average, with a TTFB of usually 650ms - it also runs much smoother and constant in terms of speed and performance than before.

 

The only reason I would consider using full Nginx (and the reason I started this thread) was because using Nginx / SPDY would allow Prestashop users to use full SSL on their website AND maybe even get some speed boosts out of it, because of the greater number of synchronous connections the Nginx / SPDY combo allows. I've seen a few tests that suggests that for websites with lots of elements (like webshops with lots of images), that could create a considerable speed boost.

Link to comment
Share on other sites

Have you seens any benchmarks on a sucha set up ?

I am really qurious to check if working with 2 webservers does actually boost load time or not

It's not running 2 servers but running nginx as reverse proxy.

 

I have such setup aslo (small shop running 1.5.6.2 on shared server using nginx as reverse proxy and SSDs and Varnish). It gives me 2-3 sec load time with all reviews, zopim chat, facebook, etc plugins and without further optimizations like CDNs, image CDNs (because of non wildcard SSL cert) and it gives me load time of under 1.5 sec for Holland (the server is located there).

 

This is for the first page with tools like pingdom, G page speed insights, etc. The second and etc pages load much faster due to some elements already being cached. The Varnish cache don't need to be tweaked, nor I have to make some PS connections with it to make it work.

 

So I think it's perfectly good and acceptable. The more load and more warmed up your cache is - the better. 

 

Try that way and they decide if you want to go nginx only.

Edited by the.rampage.rado (see edit history)
  • Like 2
Link to comment
Share on other sites

Roband have you tested nginx with multilanguage and multistore? Does it work correctly with these as well?

 

I'm using multilanguage so that works fine with my nginx config. Haven't tried multistore so don't know if some minor tweaks are needed for that.

Link to comment
Share on other sites

 

The only reason I would consider using full Nginx (and the reason I started this thread) was because using Nginx / SPDY would allow Prestashop users to use full SSL on their website AND maybe even get some speed boosts out of it, because of the greater number of synchronous connections the Nginx / SPDY combo allows. I've seen a few tests that suggests that for websites with lots of elements (like webshops with lots of images), that could create a considerable speed boost.

 

 

That's exactly what I'm doing, nginx using SPDY and full SSL on the entire website. Works great.

Link to comment
Share on other sites

That's exactly what I'm doing, nginx using SPDY and full SSL on the entire website. Works great.

 

Interesting, and it's working great? I wanted to do that too, but my hosting company advised my against using SPDY for now, as it is still experimental. Any thoughts on that?

So right now my plan is sto wait for 6 month or so and then going with SPDY, maybe it's more stable by then, especially now that Google is pushing for full SSL websites

Link to comment
Share on other sites

Interesting, and it's working great? I wanted to do that too, but my hosting company advised my against using SPDY for now, as it is still experimental. Any thoughts on that?

So right now my plan is sto wait for 6 month or so and then going with SPDY, maybe it's more stable by then, especially now that Google is pushing for full SSL websites

 

It's working fine. Wouldn't call SPDY experimental when all these sites use it 100%:

google.com

facebook.com

twitter.com

wordpress.com

Link to comment
Share on other sites

It's working fine. Wouldn't call SPDY experimental when all these sites use it 100%:

google.com

facebook.com

twitter.com

wordpress.com

 

Really? I think I need to speak with my hosting company again, because THEY called it experimental... unless they meant running Nginx on Apache and mod_spdy or what it's called, maybe they meant that.

 

Are you full Nginx or also combining Apache / Nginx ?

Link to comment
Share on other sites

Really? I think I need to speak with my hosting company again, because THEY called it experimental... unless they meant running Nginx on Apache and mod_spdy or what it's called, maybe they meant that.

 

Are you full Nginx or also combining Apache / Nginx ?

 

Full Nginx.

Link to comment
Share on other sites

×
×
  • Create New...