User Tools

Site Tools


how_to_run_litecart_on_nginx

How To Run LiteCart On Nginx

LiteCart is made for running on Apache 2.4. This article is an experimental page for all of those who are attempting to run on NginX.

Nginx configuration example

server {
  listen       80;
  server_name  mydomain.tld;
  return       301 http://www.mydomain.tld$request_uri;
}

server {
  listen       80;
  server_name  www.mydomain.tld;
  
  # Configure HTTPS and certificate
#  listen       443 ssl;
#  ssl_certificate     www.example.com.crt;
#  ssl_certificate_key www.example.com.key;
#  ssl_protocols       TLSv1.2;
  
  # Define document root and directory index
  root        "/var/www/litecart";
  index       index.php index.html index.htm;

  # Define some error pages
  error_page 401  "Access Forbidden";
  error_page 403  /error_document?code=403;
  error_page 404  /error_document?code=404;
  error_page 410  /error_document?code=410;
  error_page 500  "Internal Server Error";
  
  # Let's encrypt
  location ~ /\.well-known { 
    allow all;
  }
  
  # Deny access to apache configuration files
  location ~ /\.ht(access|passwd) { 
    deny all;
  }
  
  # Deny access to private storage
  location ^~ /(data|logs|vqmod)/ { 
    deny all;
  }
  
  # Add expire header to static content
  location ~* \.(eot|gif|ico|jpg|jpeg|otf|pdf|png|svg|ttf|woff|woff2)$ {
    expires     7d;
    add_header  Vary Accept-Encoding;
    access_log  off;
  }

  # Add shorter expire header to CSS/JS content  
  location ~* \.(css|js)$ {
    expires     1d;
    add_header  Vary Accept-Encoding;
    access_log  off;
  }
  
  # Add extra password protection to admin folder
  location /admin {
    auth_basic            "Restricted Area";
    auth_basic_user_file  /var/www/litecart/admin/.htpasswd; 
  }
  
  # Route URLs through index.php
  location / {
    try_files $uri $uri/ /index.php$is_args$args;
  }

  # Pass PHP requests to PHP-FPM
  location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    fastcgi_param  HTTP_MOD_REWRITE On;
    include        fastcgi_params;
  }

  # Pass PHP requests to FastCGI 
#  location ~ \.php$ {
#    fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
#    fastcgi_index  index.php;
#    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
#    fastcgi_param  HTTP_MOD_REWRITE On;
#    include        fastcgi_params;
#  }
}

See Also

how_to_run_litecart_on_nginx.txt · Last modified: 2020/03/03 04:11 by admin