Please help us to make AbanteCart Ideal Open Source Ecommerce Solution for everyone.

Support AbanteCart eCommerce

Author Topic: NGINX configuration  (Read 11789 times)

Offline onyxnz

  • Newbie
  • *
  • Posts: 23
  • Karma: +7/-0
    • View Profile
NGINX configuration
« on: March 17, 2017, 05:47:14 AM »
This is not a question, but rather a helper for anyone else out there that may prefer to develop on NGINX in their localhost;
My AC version is 1.2.9, laptop running Mintlinux 18.1 with Nginx 1.10 and PHP-FPM 7 and Mariadb.
Note , because it is in localhost, and I need speed, there is no SSL configuration. Ask if you need help with that.
Also, I have nginx running as me , so it is capable of writing log files to where it easiest for me to get them!

So, my /etc/nginx/sites-available/default has this added to it:

Code: [Select]
server {

        listen 80;
        server_name mydomain.com;

        access_log /home/onyx/logs/abantecart.log;
        error_log /home/onyx/logs/abantecart_error.log ;

        # root is AbanteCart's public_html directory
        root /home/onyx/htdocs/abantecart;
        index index.php index.html index.htm;

        # Prevent directory listing
        autoindex off;

        # rules applied in root of our config
        location / {

                # include AbanteCart rules
                try_files $uri $uri/ $uri.php @abantecart_rules;

                # php settings (may differ on your server)
                location ~ \.php$ {
                        #fastcgi_pass unix:/var/run/php5-fpm.sock;
#change this to suit your setup for fastcgi!!
                        fastcgi_pass   127.0.0.1:9001;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        fastcgi_param SCRIPT_NAME     $fastcgi_script_name;

                       

                        include fastcgi_params;
                }

        }

        # rewrites our query strings properly for AbanteCart
        location @abantecart_rules {
                rewrite ^(.*)\?*$ /index.php?_route_=$1 last;
        }

        # No direct access allowed for .tpl files
        location ~ \.tpl {
                deny all;
        }

}

Then in /etc/hosts you will need
Code: [Select]
127.0.0.1 mydomain.com
Don't forget you need to edit these as Superuser, and then restart the nginx server with
Code: [Select]
sudo service nginx restart
Questions and comments welcome
« Last Edit: March 17, 2017, 07:53:23 AM by onyxnz »

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 2046
  • Karma: +318/-13
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: NGINX configuration
« Reply #1 on: March 17, 2017, 05:57:00 AM »
Hi. Thank you for your post!
FYI
In the current dev-version we added nginx config example that supports SEO-keywords and rewriting rules for retina-images
See details here
https://github.com/abantecart/abantecart-src/blob/1.2.10/public_html/nginx.conf.txt

We would be glad if you checked this configuration for yourself :)
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline onyxnz

  • Newbie
  • *
  • Posts: 23
  • Karma: +7/-0
    • View Profile
Re: NGINX configuration
« Reply #2 on: March 17, 2017, 06:03:22 AM »

Thanks, will do!

Offline onyxnz

  • Newbie
  • *
  • Posts: 23
  • Karma: +7/-0
    • View Profile
Re: NGINX configuration
« Reply #3 on: March 17, 2017, 07:57:08 AM »
So, with the addition of dev-version's config, we have this:
Code: [Select]
server {

        listen 80;
        server_name mydomain.com;

        access_log /path/to/logs/abantecart.log;
        error_log /path/to/logs/abantecart_error.log ;

        # root is AbanteCart's public_html directory
        root /path/to/htdocs/abantecart;
        index index.php index.html index.htm;

        # Prevent directory listing
        autoindex off;

        # rules applied in root of our config
        location / {

                # include AbanteCart rules
                try_files $uri $uri/ $uri.php @abantecart_rules;

                # php settings (may differ on your server)
                location ~ \.php$ {
                        #fastcgi_pass unix:/var/run/php5-fpm.sock;
                        fastcgi_pass   127.0.0.1:9001;
                        #fastcgi_index index.php;

                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        fastcgi_param SCRIPT_NAME     $fastcgi_script_name;

                       

                        include fastcgi_params;
                }

        }

        # rewrites our query strings properly for AbanteCart
        location @abantecart_rules {
                rewrite ^(.*)\?*$ /index.php?_route_=$1 last;
        }

        # No direct access allowed for .tpl files
        location ~ \.tpl {
                deny all;
        }
        ### Abantecart Settings ###
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    # Make sure files with the following extensions do not get loaded by nginx because nginx would
    # display the source code, and these files can contain PASSWORDS!
    location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
        deny all;
    }
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
    ### Retina images handler. Check cookie and looking for file with @2x at the end of name
    location ~* ^(.*)\.(jpg|png|gif)$ {
        set $hidpi_uri $1@2x.png;
        if ($http_cookie !~ 'HTTP_IS_RETINA=1') {
          break;
        }
        try_files $hidpi_uri $uri =404;
    }

    location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
        expires max;
        log_not_found off;
    }
    location ~ /(system/logs|resources/download) {
      deny all;
      return 403;
    }
    location /admin/ {
        location ~ .*\.(php)?$ {
          deny all;
          return 403;
        }
    }
    #rewrite for images for retina-displays
    location ~ / {
        if (!-e $request_filename){
            rewrite ^/(.*)\?*$ /index.php?_route_=$1 last;
        }
    }


### End of AbanteCart settings ###

}

Offline Thunder_Beaver

  • Newbie
  • *
  • Posts: 5
  • Karma: +1/-0
    • View Profile
    • Freak~A~Wear (WIP)
Re: NGINX configuration
« Reply #4 on: August 22, 2020, 03:28:38 PM »
Thanks! I may try this out later.


---
I just realized this is a really old post. lol. 1.2.17 is the current version at the time of this comment.
« Last Edit: August 23, 2020, 09:46:39 PM by Thunder_Beaver »

 

Powered by SMFPacks Social Login Mod