-
-
Save marvell/ab58eacac0c4b634f595 to your computer and use it in GitHub Desktop.
Bitrix: nginx simple configuration file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
server_name examlpe.com; | |
server_name_in_redirect off; | |
proxy_set_header X-Real-IP $remote_addr; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header Host $host:80; | |
set $proxyserver "http://127.0.0.1:8888"; | |
set $docroot "/var/www/example.com/public"; | |
root $docroot; | |
index index.php; | |
access_log /var/www/example.com/logs/nginx_access.log; | |
error_log /var/www/example.com/logs/nginx_error.log; | |
# Errors | |
error_page 403 /403.html; | |
error_page 404 = @fallback; | |
error_page 500 502 503 504 /500.html; | |
# Custom BitrixEnv errors page | |
location @fallback { proxy_pass $proxyserver; } | |
# Html cache | |
location ~ ^(/bitrix/html_pages) { | |
index index@.html; | |
include conf/security.conf; | |
if (!-f $request_filename) { | |
rewrite ^/bitrix/html_pages(.*)/index@.html$ $1/ break; | |
rewrite ^/bitrix/html_pages(.*)/index@(.*)\.html$ $1/?$2 break; | |
rewrite ^/bitrix/html_pages(.*)@.html$ $1.php break; | |
rewrite ^/bitrix/html_pages(.*)@(.*)\.html$ $1.php?$2 break; | |
proxy_pass $proxyserver; | |
} | |
} | |
# Php | |
location ~ \.php$ { | |
include conf/security.conf; | |
if ($request_method = POST ) { | |
break; | |
proxy_pass $proxyserver; | |
} | |
# Engine Bitrix html cache | |
set $usecache ""; | |
if ($http_cookie !~ "PHPSESSID=" ) { set $usecache "Y"; } | |
if (-f "$docroot/bitrix/html_pages/.enabled") { set $usecache "${usecache}Y"; } | |
if ($usecache = "YY" ) { rewrite ^(.*)\.php$ /bitrix/html_pages$1@$args.html? last; } | |
proxy_pass $proxyserver; | |
} | |
# Php | |
location ~ /$ { | |
include conf/security.conf; | |
if ($request_method = POST ) { | |
break; | |
proxy_pass $proxyserver; | |
} | |
set $usecache ""; | |
if ($http_cookie !~ "PHPSESSID=" ) { set $usecache "Y"; } | |
if (-f "$docroot/bitrix/html_pages/.enabled") { set $usecache "${usecache}Y"; } | |
if ($usecache = "YY" ) { rewrite ^(.*)/$ /bitrix/html_pages$1/index@$args.html? last; } | |
proxy_pass $proxyserver; | |
} | |
# Deny access to cache and grant to css and js pack | |
location ^~ /bitrix/cache { | |
deny all; | |
} | |
location ^~ /bitrix/cache/css/ { | |
location ~* ^.+.(css)$ { | |
expires 30d; | |
error_page 404 /404.html; | |
} | |
location ~* .*$ { | |
deny all; | |
} | |
} | |
location ^~ /bitrix/cache/js/ { | |
location ~* ^.+.(js)$ { | |
expires 30d; | |
error_page 404 /404.html; | |
} | |
location ~* .*$ { | |
deny all; | |
} | |
} | |
# Deny some paths | |
location ~ /\.ht { deny all; } | |
location ~ /\.hg { deny all; } | |
location ~ /.svn/ { deny all; } | |
location ^~ /bitrix/modules { deny all; } | |
location ^~ /bitrix/local_cache { deny all; } | |
location ^~ /bitrix/stack_cache { deny all; } | |
location ^~ /bitrix/managed_cache { deny all; } | |
location ^~ /bitrix/php_interface { deny all; } | |
location ^~ /upload/support/not_image { deny all; } | |
location ~* /upload/1c_(.*)/(.*) { deny all; } | |
# Static files | |
location ^~ /upload { expires 30d; error_page 404 /404.html; } | |
location ^~ /bitrix/images { expires 30d; error_page 404 /404.html; } | |
location ^~ /bitrix/tmp { expires 30d; error_page 404 /404.html; } | |
# Apache server status | |
location ^~ /server-status { proxy_pass $proxyserver; } | |
# Nginx server status | |
location ^~ /nginx-status { | |
stub_status on; | |
allow 127.0.0.0/24; | |
deny all; | |
} | |
# main location | |
location / { | |
expires 15d; | |
include conf/security.conf; | |
# dav processing | |
if ($request_method ~ ^(PROPFIND|OPTIONS|COPY|MOVE|PROPPATCH|MKCOL|LOCK|UNLOCK|PUT|REPORT|SEARCH|MKCALENDAR)$) { proxy_pass $proxyserver; } | |
# Error page for static content | |
if ($request_filename ~* \.(css|js|gif|png|jpg|jpeg|ico)$) { | |
error_page 404 /404.html; | |
break; | |
} | |
} | |
# Bitrix setup script | |
location ^~ ^(/bitrixsetup\.php)$ { proxy_pass $proxyserver; proxy_buffering off; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment