Skip to content

Instantly share code, notes, and snippets.

@mjau-mjau mjau-mjau/nginx.conf
Last active Dec 20, 2018

Embed
What would you like to do?
X3 NGINX config
server {
# Basic NGINX site setup
listen 80;
server_name yourwebsite.com;
# 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 [OPTIONAL]
# 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:
fastcgi_pass 127.0.0.1:9000;
# 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;
}
}
@mjau-mjau

This comment has been minimized.

Copy link
Owner Author

commented Apr 2, 2017

X3 NGINX
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:
https://github.com/h5bp/server-configs-nginx

PHP
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:
https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/
https://www.sitepoint.com/setting-up-php-behind-nginx-with-fastcgi/

@mjau-mjau

This comment has been minimized.

Copy link
Owner Author

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;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.