Installing Elgg on Nginx

To run Elgg on Nginx, you will need to:

  • configure Nginx to talk to a PHP process in either CGI or FPM mode

  • Port the following rewrite rules

# Elgg Nginx configuration. Customize and put into /etc/nginx/sites-enabled

# Rewrite http://(www.)?example.org to https://example.org

#server {
#	listen 80;
#	server_name example.org www.example.org;
#	rewrite ^ https://example.org$request_uri permanent;
#}

# Rewrite https://www.example.org to https://example.org

#server {
#	include /etc/nginx/ssl.conf;
#	server_name www.example.org;
#	rewrite ^ https://example.org$request_uri? permanent;
#}

server {
	listen 80;
	server_name example.org;

	# Server root, replace it with your elgg installation location
	root /var/www/$server_name;
	index index.php index.html index.htm;
	
	gzip on;
	gzip_types
		# text/html is always compressed by HttpGzipModule
		text/css
		text/javascript
		text/xml
		text/plain
		text/x-component
		application/json
		application/xml
		application/rss+xml
		font/truetype
		font/opentype
		application/vnd.ms-fontobject
		image/svg+xml;

	# Server logs, replace it with your project names
	error_log /var/log/nginx/$server_name.error.log error;
	access_log /var/log/nginx/$server_name.access.log;

	# Max post size
	client_max_body_size 8M;

	location ~ /.well-known {
        	allow all;
	}

	location ~ (^\.|/\.) {
		return 403;
	}

	location = /rewrite.php {
		rewrite ^(.*)$ /install.php;
	}

	location / {
		try_files $uri $uri/ @elgg;
	}

	location /cache/ {
		disable_symlinks off;
		expires 1y;
		try_files $uri $uri/ @elgg;
	}

	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	location ~ \.php$ {
		try_files $uri @elgg;
		fastcgi_index index.php;
		fastcgi_pass localhost:9000;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include /etc/nginx/fastcgi_params;
	}

	location @elgg {
		fastcgi_pass localhost:9000;

		include /etc/nginx/fastcgi_params;
		fastcgi_param SCRIPT_FILENAME $document_root/index.php;
		fastcgi_param SCRIPT_NAME     /index.php;
	}
}

Other than that, you should be able to follow the standard installation instructions.