Installation / Webserver / NGINX Configuration
NGINX is a high-performance web server that is capable of serving thousands of request while using fewer resources than other servers like Apache.
Unlike Apache, NGINX focuses on performance and as such does not have the
concept of .htaccess
files that applications such as Bolt use to set per-site
configuration. Below are details on how to effect the same changes for you Bolt
sites.
Configuration¶
NGINX configuration best is broken up into site configuration files that are unique to an individual site, and common, or "global", configuration settings that can be reused by individual sites.
Individual Site¶
Generally, NGINX site configuration files live in /etc/nginx/conf.d/
and are
loaded automatically when their file names end in .conf
.
It is good practice to name your configuration file after the domain name of
your site, in this example our site is example.com
so the configuration file
would be called example.com.conf
.
An example of what a /etc/nginx/conf.d/example.com.conf
file might look like:
NOTE: You will need to customise/change the values for the server_name
,
access_log
, error_log
and root
parameters to match the domain name and
path locations relevant to your system.
Common¶
Common, or "global", configuration settings are stored in a directory under
/etc/nginx/
. For our examples we use the /etc/nginx/global/
directory for
no other reason besides semantics.
This section contains details on the following files:
File name | Description |
---|---|
bolt.conf |
Bolt specific routes |
restrictions.conf |
Files & directories to block access to |
php-fpm.conf |
PHP-FPM configuration |
bolt.conf
¶
The bolt.conf
file define location matches common to all of your Bolt sites
on a host.
restrictions.conf
¶
The restrictions.conf
file defines a common set of restrictions for all of
your Bolt sites on a host.
php-fpm.conf
¶
The php-fpm.conf
file define the settings for the PHP FastCGI Process Manager
used for you Bolt site(s).
On larger multi-CPU hosts with several busy sites, you will no doubt want to use several FPM pools, with each pool defining their own socket. You can simply use one of these files per-pool.
NOTE: You must enable one of the fastcgi_pass
parameters, or NGINX
will attempt to initiate a download of the index.php
file instead of
executing it.
Subfolders¶
To install Bolt within a subfolder, a location describing this must be added.
Two previously added locations must be amended.
NGINX Location Matching¶
Location matching in NGINX is usually the part that causes the most headaches for people. NGINX has a strict matching priority which is explained in greater detail in their documentation.
In summary, locations are matched in order based on the type of modifier used. The following table outlines each modifier in their order of priority.
Modifier | Description | Example |
---|---|---|
= | Exact match of the specific URI | location = /path {} |
^~ | Strict forward match | location ^~ /path {} |
~ | Regular expression (case-sensitive) | location ~ /path/ {} |
~* | Regular expression (case_insensitive) | location ~* .(gif |jpg |png) {} |
/ | Prefix location match | location /path {} |
Note:
- If an exact match
=
is found, the search terminates /
matches any request as all requests begin with a/
, but regular expressions, and longer prefixed locations will be matched first^~ /path/
matches any request starting with/path/
and halts searching, meaning further location blocks are not checked- If the longest matching prefix location has the
^~
modifier then regular expressions are not checked ~* \.(gif|jpg|png)$
matches any request ending ingif
,jpg
, orpng
. But if these image files are in the/path/
directory, all requests to that directory are handled by the^~ /path/
location block (if set), as it has ordering priority/path/
matches any request starting with/path/
and continues searching, and will be matched only if regular expressions do not match
The helpful NGINX Location Match tool is very useful for testing location match blocks, and gives visual graphs to explain NGINX's logic.
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on Github.