Login/Signup

Prestashop-Sync Service is aimed to help merchants that use Prestashop platform in solving their everyday routines.

Notice: Prestashop Sync Servive website is not the official PrestaShop site.

Nginx in front of Apache Prestashop configuration

Usually Prestashop is installed on the Apache webserver, this case is also described in the official Prestashop documentation.

However Apache, being a super webserver as itself, have a number of shortcomings.
The most important one is much higher CPU and memory load when dealing with static content like images, javascript and css styles.

So in this article we will configure separate lightweight http server Nginx as a front end to Apache. Of course, using Prestashop as an example.
You can find detailed performance comparision of Apache and Nginx here:
https://nbonvin.wordpress.com/2011/03/14/apache-vs-nginx-vs-varnish-vs-gwan/

It is assumed that you have some debian/ubuntu linux as an operating system on your server where Prestashop is installed.

  1. First of all we will install nginx:
    aptitude install nginx
  2. Create nginx configuration file for proxied requests – /etc/nginx/proxy.conf:
    proxy_redirect          off;
    proxy_set_header        Host             $host;
    proxy_set_header        X-Real-IP        $remote_addr;
    proxy_set_header        X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header        Range            "";
    proxy_set_header        Request-Range    "";
    client_max_body_size    10m;
    client_body_buffer_size 128k;
    proxy_connect_timeout   90;
    proxy_send_timeout      90;
    proxy_read_timeout      90;
    proxy_buffers           16 128k;
    proxy_busy_buffers_size 128k;
    proxy_buffer_size       128k;
    
  3. Two webservers cannot listen the same port on the server – thus we need to switch Apache on another port. Edit /etc/apache2/ports.conf file to do that:
    Listen 127.0.0.1:80
  4. Then create nginx configuration file for our shop – /etc/nginx/sites-available/myshop:
    server {
        listen IP.XXX.XXX.XXX:80;    
        server_name myshop.ru www.myshop.ru;
        # Унифицируем домен
        if ($host = 'www.myshop.ru' ) {
          rewrite ^/(.*)$ http://myshop.ru/$1 permanent;
        }
        location ~ ^.+\.(jpg|jpeg|gif|png|ico|css|js)$ {
        root /var/www/myshop;
        expires max;
        access_log off;
        rewrite "^/([a-z]{2})/js/(.+)$" /js/$2 last;
        rewrite ^/([a-z0-9]+)\-([a-z0-9]+)(\-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)\.jpg$ /img/p/$1-$2$3.jpg last;
        rewrite ^/([0-9]+)\-([0-9]+)/([_a-zA-Z0-9-]*)\.jpg$ /img/p/$1-$2.jpg last;
        rewrite ^/([0-9]+)(\-[_a-zA-Z0-9-]*)/([_a-zA-Z0-9-]*)\.jpg$ /img/c/$1$2.jpg last;
        }
        location / {
        proxy_pass   http://127.0.0.1:8080;
        include /etc/nginx/proxy.conf;
        }
    }
    
    Here you need to replace myshop with the real domain name of your shop.
  5. At last we should activate our Nginx server and restart Apache:
    cd /etc/nginx/sites-enabled
    ln -s /etc/nginx/sites-available/myshop myshop
    service apache2 restart
    service nginx restart
    
  6. If everything is configured properly, then you should be able to access shop site as before, but it will work much faster :)

As a bonus, Nginx also protects our Apache server from two recently found vulnerabilities, exploiting which any person could sent your internet store to offline:

Meta

Published: Aug. 28, 2011

Author:

Next: Как создавался новый prestashop-sync.com

Bookmark and Share

Tags

apache configuration nginx prestashop ubuntu

Comments powered by Disqus