NGINX config for Opencart

Posted by Oleh Vasylyev 17/05/2017 0 Comment(s)

You find below NGINX config (NGINX + PHP_fpm configuration)

 

Create a new virtual host configuration file for OpenCart in the Nginx 'conf.d' directory. Go to the Nginx virtualhost directory and create new configuration

 

server {
    server_name www.mydomain.com; ## Your Domain
    root /var/www/opencart; ## Web Root Directory
    index index.php index.html;
    listen 80;
    listen [::]:80;
    listen 443 default ssl;
    ssl_certificate      /etc/nginx/ssl/mydomain.crt;
    ssl_certificate_key  /etc/nginx/ssl/mydomain.key;
    # Redirect HTTP to HTTPS
    if ($scheme = http) {
        return 301 https://$server_name$request_uri;
    }
    access_log /var/log/nginx/myopencart_access.log;               
    location /image/data {
        autoindex on;
    }
    location /admin {
        index index.php;
    }
    location / {
        try_files $uri @opencart;
    }
    location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }
    
    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
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
    location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
        expires max;
        log_not_found off;
    }
    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

Tags: nginx

Leave a Comment