Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
X3 NGINX config
server {
# Basic NGINX site setup
listen 80;
# Location where X3 is installed
root /var/www/yourwebsite;
# index.php as index
index index.php;
# X3 rewrite rules
location / {
if (!-e $request_filename){
# Rewrite any calls to html|json|xml|atom|rss if a folder matching * exists
rewrite (.+)\.(html|json|xml|atom|rss)$ $1/ last;
# Rewrite any calls to /render to the X3 image resizer
rewrite ^/render/. /app/parsers/slir/ last;
# Rewrite routes to X3 application index.php if they are non-existent files/dirs
rewrite ^(.*)$ /index.php?$1 last;
# Prevent web access to X3 /config and /_cache directories
location ~ /(config|_cache) {
deny all;
# PHP setup may vary, but you should already have PHP working for NGINX or for a website.
# Likely you may have a php.conf file to include.
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# With php5-cgi alone:
# With php5-fpm:
# fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;

This comment has been minimized.

Copy link
Owner Author

@mjau-mjau mjau-mjau commented Apr 2, 2017

The above is the minimum code required to run X3 on NGINX server. It does not assume any other settings that are not crucial for X3 to function properly. If you require more information about additional and recommended NGINX rules, you may wish to check the H5BP (HTML5Boilerplate) NGINX server config examples:

Since you are running NGINX, it is assumed you already have PHP running properly, and know how to apply it to a new website. In the example above, there is a standard example of how to enable PHP for X3, but it requires PHP to be available with either php5-cgi or php5-fpm naturally. You can find more info about running PHP with NGINX in the below links:


This comment has been minimized.

Copy link
Owner Author

@mjau-mjau mjau-mjau commented May 3, 2017

If you are installing X3 in a sub-directory, you will need to modify the X3 rewrite rules to include the sub-directory path. For example, if you installed X3 in sub-directory /x3/, rewrite rules will be:

# X3 rewrite rules for sub-directory /x3
location /x3 {
  if (!-e $request_filename){
    rewrite (.+)\.(html|json|xml|atom|rss)$ $1/ last;
    rewrite ^/x3/render/. /x3/app/parsers/slir/ last;
    rewrite ^/x3/(.*)$ /x3/index.php?$1 last;

This comment has been minimized.

Copy link

@nicky1605 nicky1605 commented Jan 17, 2021

Hi. If you use location ~ /(config|_cache)will only protect this folder, but the PHP files in the folder can be accessed. It should be changed to location ^~ /(config|_cache)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment