2011-02-07 07:48:44 +01:00
# Nginx
2014-03-10 10:48:22 +01:00
These instructions are also covered on the
2012-12-14 23:26:13 +01:00
[Nginx Wiki ](http://wiki.nginx.org/SilverStripe ).
2011-02-07 07:48:44 +01:00
2012-12-14 23:26:13 +01:00
The prerequisite is that you have already installed Nginx and you are
able to run PHP files via the FastCGI-wrapper from Nginx.
2011-02-07 07:48:44 +01:00
2013-04-22 01:51:00 +02:00
Now you need to set up a virtual host in Nginx with configuration settings
that are similar to those shown below.
< div class = "notice" markdown = '1' >
If you don't fully understand the configuration presented here, consult the
[nginx documentation ](http://nginx.org/en/docs/ ).
Especially be aware of [accidental php-execution ](https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/ "Don't trust the tutorials" ) when extending the configuration.
< / div >
But enough of the disclaimer, on to the actual configuration — typically in `nginx.conf` :
2011-02-07 07:48:44 +01:00
server {
2012-12-14 23:26:13 +01:00
listen 80;
2014-03-10 10:48:22 +01:00
root /path/to/ss/folder;
2011-02-07 07:48:44 +01:00
2014-03-10 10:48:22 +01:00
server_name site.com www.site.com;
2011-02-07 07:48:44 +01:00
2014-03-10 10:48:22 +01:00
location / {
try_files $uri /framework/main.php?url=$uri&$query_string;
2013-04-22 01:51:00 +02:00
}
2011-02-07 07:48:44 +01:00
2014-03-10 10:48:22 +01:00
error_page 404 /assets/error-404.html;
2013-04-22 01:51:00 +02:00
error_page 500 /assets/error-500.html;
2014-03-10 10:48:22 +01:00
location ^~ /assets/ {
sendfile on;
try_files $uri =404;
}
2013-04-22 01:51:00 +02:00
2014-03-10 10:48:22 +01:00
location ~ /framework/.*(main|rpc|tiny_mce_gzip)\.php$ {
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
2013-04-22 01:51:00 +02:00
2014-03-10 10:48:22 +01:00
location ~ /(mysite|framework|cms)/.*\.(php|php3|php4|php5|phtml|inc)$ {
deny all;
}
2011-02-07 07:48:44 +01:00
2014-03-10 10:48:22 +01:00
location ~ /\.. {
deny all;
}
2011-02-07 07:48:44 +01:00
2014-03-10 10:48:22 +01:00
location ~ \.ss$ {
satisfy any;
allow 127.0.0.1;
deny all;
}
2011-02-07 07:48:44 +01:00
2014-03-10 10:48:22 +01:00
location ~ web\.config$ {
deny all;
}
2013-01-29 02:11:52 +01:00
2014-03-10 10:48:22 +01:00
location ~ \.ya?ml$ {
deny all;
}
location ^~ /vendor/ {
deny all;
}
location ~* /silverstripe-cache/ {
deny all;
}
location ~* composer\.(json|lock)$ {
deny all;
}
location ~* /(cms|framework)/silverstripe_version$ {
deny all;
}
location ~ \.php$ {
2014-11-18 21:56:40 +01:00
fastcgi_keep_conn on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_buffer_size 32k;
fastcgi_busy_buffers_size 64k;
fastcgi_buffers 4 32k;
2014-03-10 10:48:22 +01:00
}
2011-02-07 07:48:44 +01:00
}
2012-12-14 23:26:13 +01:00
2014-03-10 10:48:22 +01:00
The above configuration sets up a virtual host `site.com` with
rewrite rules suited for SilverStripe. The location block for php files
passes all php scripts to the FastCGI-wrapper via a TCP socket.
2011-02-07 07:48:44 +01:00
Now you can proceed with the SilverStripe installation normally.