How To Run LiteCart On Nginx

NginX doesn't support Apache's .htaccess files and need it's own configuration to display a website. This is an example configuration for running LiteCart on NginX.

/etc/nginx/conf.d/nginx.conf :

events {
  ...
  worker_connections  1024;
  ...
}

http {
  ...
  include   mime.types;
  ...
  include  "vhosts/litecart.conf";
 ...
}

/etc/nginx/conf.d/vhosts/mydomain.tld.conf:

server {

  server_name mydomain.tld;  # Change to your domain/subdomain

  listen  80;  # Default port 80 (non-secure HTTP)

  #listen  443 ssl;  # Uncomment for HTTPS
  #ssl_certificate /etc/ssl/certs/domainname-ssl-bundle.crt;
  #ssl_certificate_key /etc/ssl/private/domainname.key;

  root  "/webpath/to/litecart";  # Usually "/"
  index  index.php index.html index.htm;

  # Application
  location / {
    rewrite  ^/(cache|images)/ /$request_uri last;
    try_files  $uri $uri/ /index.php$is_args$args;
  }

  # PHP
  location ~ .php$ {
    include        conf/fastcgi_params;

    #fastcgi_pass   127.0.0.1:9123;  # Using PHP-FPM TCP/IP socket, make sure the port number is right
    fastcgi_pass   unix:/run/php/php8.1-fpm.sock;  # Using PHP-FPM files socket

    fastcgi_param  REDIRECT_HTTP_MOD_REWRITE  On;  # Enables LiteCart's URL rewriting
  }

  # Static content cache and compression
  location ~ .(a?png|avif|bmp|css|eot|gif|ico|jpe?g|jp2|js|otf|pdf|svg|tiff?|ttf|webp|woff2?)$ {
    expires  2w;
    gzip_static  on;
  }

  # Deny access to some files
  location ~ .(htaccess|htpasswd|inc.php)$ {
    deny  all; 
  }

  # Deny access to some directories
  location ~ ^/(data|logs|vendor|vmods|vqmod)/ {
    deny  all;
  }
}

See Also

Revisiones

Editores principales
Artículos editados recientemente