Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
location ~* /forum/(.*)\.php$
{
proxy_pass ;
if ($country = 'en') { return 404; }
}
location ~* /forum/
{
if ($country = 'en') { return 404; }
}
location ~* "/forum/(.*)\.(jpg|jpeg|gif|png|bmp|ico|swf|flv|css|txt|xml|rss|js)$"
{
expires max;
if ($country = 'en') { return 404; }
}.<code>location /forum
{
if ($country = 'en') { return 404; }
location ~ \.php$
{
proxy_pass ...;
}
location ~* "\.(jpg|jpeg|gif|png|bmp|ico|swf|flv|css|txt|xml|rss|js)$
{
expires max;
}
}</code>use php-conf
{
fastcgi_pass ...;
}
location ~ \.php$
{
use php-conf;
}
location @fallback
{
use php-conf;
}location ~ \.html$
{
root cache;
error_page 406 =@indexphp;
if ( $request_method = 'POST' ) { return 406; }
try_fiiles $uri @indexphp;
}
location @indexphp
{
fastcgi_pass ...;
fastcgi_param script_FILENAME $document_root/index.php;
include fastcgi_params;
}</code>
Тут мы по error_page .. if .. return или try_files уходим в другой location, когда кеширование неприменимо.
Если бекенд - apache, то можно написать что-то такое:
location ~ \.html$
{
root cache;
error_page 406 =/index.php;
if ( $request_method = 'POST' ) { return 406; }
try_fiiles $uri /index.php;
}
location =/index.php
{
proxy_pass ...;
}</code>
Вообще, для подобного есть встроенное кеширование nginx, которое работает для proxy_pass и fastcgi_pass, учитывает и отсутствие файла, и POST, и истечение. Есть замечательная статья по этому поводу: dklab.ru/chicken/nablas/56.html server {
listen 80;
server_name blabla.ru *.blabla.ru "";
if ($host != blabla.ru ) {
rewrite ^(.*)$ httр://blabla.ru$1 permanent;
}
proxy_cache_use_stale http_503; proxy_cache_valid 200 301 302 304 1ms;
<code>
location = /subdir/index.php
{
root /var/www/example.com/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param script_FILENAME $document_root$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGHT $content_length;
include fastcgi_params;
}
location ~ /subdir/(.*)$
{
root /var/www/example.com/www;
try_files $uri /subdir/iindex.php?/$1;
}<code>
location = /subdir/index.php
{
root /var/www/example.com/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param script_FILENAME $document_root/subdir/index.php;
fastcgi_param QUERY_STRING $request_uri;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGHT $content_length;
include fastcgi_params;
}
location ~ /subdir/(.*)$
{
root /var/www/example.com/www;
try_files $uri @fallback;
}
Ошибки конфигурирования nginx (или как правильно писать рерайты)