User Tools

Site Tools


how_to_run_litecart_on_nginx

How To Run LiteCart 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;
#  }
}

Turn CentOS 7 into a LEMP Server (May contain errors)

#!/bin/sh

## Install EPEL and REMI repositories
rpm -Uvh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

## Install some tools
sudo yum install -y nano curl

## Install NGINX
sudo yum install -y nginx

## Install PHP and PHP-FPM
sudo yum install -y php php-fpm php-bcmath php-gd php-mbstring php-mcrypt php-mysqlnd php-soap php-zip

## Configure PHP-fpm (see below)
sudo nano /etc/php-fpm.d/www.conf
#[myuser] group=mygroup

## Install MariaDB/MySQL
sudo yum install -y mariadb-server

# Install phpMyAdmin
sudo yum install -y phpmyadmin
#sudo chgrp -R nginx /etc/phpMyAdmin

## Configure NGINX (see below)
sudo nano /etc/nginx/conf.d/phpmyadmin.conf
#location /phpMyAdmin {
#    root /usr/share/;
#    index index.php index.html index.htm;
#    location ~ ^/phpMyAdmin/(.+\.php)$ {
#      try_files $uri =404;
#      root /usr/share/;
#      fastcgi_pass unix:/run/php-fpm/www.sock;
#      fastcgi_index index.php;
#      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#      include /etc/nginx/fastcgi_params;
#    }
#    location ~* ^/phpMyAdmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
#        root /usr/share/;
#    }
#}
#location /phpmyadmin {
#    rewrite ^/* /phpMyAdmin last;
#}

## Configure NGINX (see below)
sudo nano /etc/nginx/nginx.conf
#server {
#    listen       80;
#    server_name  localhost;
#
#    root   /usr/share/nginx/html;
#    index  index.php index.html index.htm;
#
#    location / {
#        try_files $uri $uri/ =404;
#    }
#    error_page 404 /404.html;
#    error_page   500 502 503 504  /50x.html;
#    location = /50x.html {
#        root   /usr/share/nginx/html;
#    }
#    location ~ \.php$ {
#        try_files $uri =404;
#        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
#        fastcgi_index index.php;
#        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#        include fastcgi_params;
#    }
#}

## Configure PHP-FPM (see below)
sudo nano /etc/php-fpm.d/www.conf
#listen = /var/run/php-fpm/php-fpm.sock
#listen.owner = nobody
#listen.group = nobody
#user = nginx
#group = nginx

## Start services upon boot sequence
sudo chkconfig nginx on
sudo chkconfig php-fpm on
sudo chkconfig mysqld on

## Start services immediately
sudo service nginx start
sudo service php-fpm start
sudo service mysqld start

## Create index.php (echo hello world or phpinfo())
sudo nano /var/www/html/index.php

## Install command line browser
sudo yum install -y lynx

## Open the browser (use Ctrl-Z to exit)
lynx http://localhost/

## Install Ajenti control panel
curl https://raw.githubusercontent.com/ajenti/ajenti/1.x/scripts/install-rhel7.sh | sudo sh
how_to_run_litecart_on_nginx.txt · Last modified: 2019/02/21 00:58 by 90.230.2.167