User Tools

Site Tools


running_backlight_on_nginx_web_server

Running Backlight on Nginx Web Server

The Turning Gate fully supports Backlight on Apache servers running on Linux. Some customers prefer to host on other web servers, such as IIS and Nginx. While Backlight should work in those environments, we do not have the resources to fully test Backlight in environments beyond Apache/Linux. As such, any support is provided on a best-effort basis.

Backlight should run on Nginx web servers with no modification to the code itself. It is essential that the site be configured properly on the web server, in particular to protect data files and digital purchases from direct downloads.

Configuration of Nginx to run PHP, and general site configuration is beyond the scope of this page.

Setting up Backlight on Nginx is performed in two steps:

  1. Configuring Nginx to protect data and cart purchase directories
  2. Optionally, configure Backlight to use Clean URLs for Page and image links

Configuring Nginx

Below are entries to be added to your Nginx server configuration for Backlight compatibility. These assume that your site is running at the root, and not in a subdirectory, e.g. at http://yoursite.com/

# protect against direct downloads of data files
location /backlight/data/ {
    return 404;
}

# protect against direct downloads of digital purchases
rewrite ^(.*)/(.*)/photos-for-purchase/* / last;

# clean URLs for single image pages
rewrite ^(.*)/(.*)-single.php $1/single.php?id=$2 last;

# clean URLs for Pages
location / {
    # This is cool because no php is touched for static content
    try_files $uri $uri/ /index.php;

    if (-f $request_filename) {
        break;
    }
    if (-d $request_filename) {
        break;
    }

    rewrite ^/(.*) /index.php?page=$1 last;
}

Below is a complete server configuration for a website that incorporates the above additions:

server { 
	## Your only path reference. 
	root /srv/www/yoursite.com/public_html; 
	listen 80; 
	
	## Your website name goes here. Change to domain.ltd in VPS 
	server_name backlight.pi; 
	access_log /srv/www/yoursite.com/logs/access.log; 
	error_log /srv/www/yoursite.com/logs/error.log; 
	
	## This should be in your http block and if it is, it's not needed here. 
	index index.php; 
	
	location = /favicon.ico { 
		log_not_found off; 
		access_log off; 
	} 
	
	location = /robots.txt { 
		allow all; 
		log_not_found off; 
		access_log off; 
	} 

        location ~* (ttg-be/data|photos-for-purchase) {
                deny all;
                autoindex off;
        }
	
	location ~ \.php$ { 
		#NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 
		include fastcgi_params; 
		fastcgi_intercept_errors on; 
		fastcgi_pass php; 
	} 
	
	location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { 
		expires max; log_not_found off; 
	} 

        rewrite ^(.*)/(.*)-single.php $1/single.php?id=$2 last;

        location /backlight/data/ {
		return 404;
	}

        rewrite ^(.*)/(.*)/photos/* / last;

        location / {
                # This is cool because no php is touched for static content
                try_files $uri $uri/ /index.php;

                if (-f $request_filename) {
                        break;
                }
                if (-d $request_filename) {
                        break;
                }

                rewrite ^/(.*) /index.php?page=$1 last;
        }
}

Configuring Backlight to support Clean URLs

Clean URLs are used for pages and single image links, and take the format of http://yoursite.com/about-us/ rather than http://yoursite.com/?page=about-us, and http://yoursite.com/galleries/album/image1000-single.php rather than http://yoursite.com/galleries/album/single.php?id=image1000

Backlight is unable to automatically detect that clean URLs should be used on Nginx installations. Backlight 1.0.4 or newer supports a setting to force Backlight to generate clean URLs for pages and single images. Only make the following change if you have added support for clean URLs in your Nginx server config, as outlined above.

To force generation of clean URLs:

  1. Copy or rename the file backlight/env.php.skel to backlight/env.php on your server
  2. Uncomment the setting for FORCE_CLEAN_URLS near the end of that file by removing the leading //, so that the line reads:
define('FORCE_CLEAN_URLS', true);
running_backlight_on_nginx_web_server.txt · Last modified: 2016/08/12 02:32 by ben