Difference between revisions of "Nginx"
From Alessandro's Wiki
| Line 16: | Line 16: | ||
*; location { } | *; location { } | ||
* not logging if the site icon does not exists: | |||
location = /favicon.ico { | location = /favicon.ico { | ||
log_not_found off; | log_not_found off; | ||
access_log off; | access_log off; | ||
} | |||
* denying a directory: | |||
location = /directory_to_hide { | |||
deny all; | |||
} | |||
* allow certain files only to local lan: | |||
location ~* \.(txt|logs)$ { | |||
allow 192.168.0.0/24; | |||
deny all; | |||
} | |||
* block files by extension: | |||
location ~* \.(inc|engine|install|info|module|sh|sql|theme|tpl\.php|xtmpl|Entries|Repository|Root|jar|java|class)$ { | |||
deny all; | |||
} | } | ||
Revision as of 14:30, 1 October 2012
Configuration
- server { }
listen 80; server_name thedomain.com;
access_log logs/access.log; error_log logs/error.log;
root /home/swin/oaih/dev/public; index index.php index.html index.htm;
- location { }
- not logging if the site icon does not exists:
location = /favicon.ico {
log_not_found off;
access_log off;
}
- denying a directory:
location = /directory_to_hide {
deny all;
}
- allow certain files only to local lan:
location ~* \.(txt|logs)$ {
allow 192.168.0.0/24;
deny all;
}
- block files by extension:
location ~* \.(inc|engine|install|info|module|sh|sql|theme|tpl\.php|xtmpl|Entries|Repository|Root|jar|java|class)$ {
deny all;
}
FastCGI
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location ~ .php($|/) {
set $script $uri;
set $path_info "";
if ($uri ~ "^(.+.php)(/.+)") {
set $script $1;
set $path_info $2;
}
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$script;
fastcgi_param SCRIPT_NAME $script;
fastcgi_param PATH_INFO $path_info;
}
Rewrite rules
- rewriting every non existent file to index.php
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php/$1 last;
}
}