Skip to content

Instantly share code, notes, and snippets.

@mlocati
Created Dec 24, 2015
Embed
What would you like to do?
concrete5 under nginx

Here's a very basic nginx configuration for a website running concrete5:

# Define the server configuration
server {
	# Define the ports the server is listening to
	# In case this is the default website, you can add default_server before the semicolon
	listen 80;
	listen [::]:80 ipv6only=on;

	# In case of multiple websites for the same IP and port, you can specify the specific host
	# name for this web server by uncommenting this line
	# server_name www.example.com;

	# Define the root directory served by nginx.
	# Replace PATH with the full path of the concrete5 installation
	root PATH;

	# Block access to the .htaccess files (eg urls containing "/.ht")
	location ~ /\.ht {
		deny all;
	}

	# Define the default documents to be served when users browse to a directory
	index index.html index.htm index.php;

	# Enable using concrete5 pretty urls
	location / {
		try_files $uri $uri/ /index.php$uri;
	}

	# Executes PHP scripts (ie urls ending with ".php" or containing ".php/")
	location ~ .\.php($|/) {

		# Set "index.php" as the file name that will be appended after a URI that ends with a slash
		fastcgi_index index.php;

		# Define these two variables (for the two captured groups):
		# - $fastcgi_script_name
		# - $fastcgi_path_info
		fastcgi_split_path_info ^(.+?\.php)(/.*)$;

		# Set the values of some default variables.
		# See https://www.nginx.com/resources/wiki/start/topics/examples/fastcgiexample/
		# For Debian-based systems you may have the following line:
		include fastcgi_params;

		# Set the value of SCRIPT_FILENAME
		# $document_root is defined by the "root" directive above
		# $fastcgi_script_name is the relative path to the php script being launched
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

		# Set the address of the FastCGI server.
		# For Debian-based systems it may be something like this:
		fastcgi_pass unix:/var/run/php5-fpm.sock;

	}
}

In case you have concrete5 installed in a sub-directory of your document root (for instance c5root), you have to change this:

	location / {
		try_files $uri $uri/ /index.php$uri;
	}

to

	location /c5root/ {
		try_files $uri $uri/ /c5root/index.php$uri;
	}
@devzorg

This comment has been minimized.

Copy link

@devzorg devzorg commented Oct 19, 2016

doesn't work (nginx 1.10.1)

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