Skip to content

Instantly share code, notes, and snippets.

@diproart
Last active April 21, 2021 18:55
Show Gist options
  • Select an option

  • Save diproart/4189907a00514c3df5b4 to your computer and use it in GitHub Desktop.

Select an option

Save diproart/4189907a00514c3df5b4 to your computer and use it in GitHub Desktop.
Bitrix 15.x.x / Php-Fpm / Nginx
# bitrix virtual host
# @version 1.0.1
server {
set $id user;
set $domain server.com;
set $folder default;
set $socket unix:/var/run/php5-bx-fpm.sock;
charset utf-8;
listen 80;
# nginx server_name resolution order
# ---
# + exact name
# + longest wildcard name starting with an asterisk, e.g. “*.example.org”
# + longest wildcard name ending with an asterisk, e.g. “mail.*”
# + first matching regular expression (in order of appearance in a configuration file)
# if use $domain we maybe have some truble fro name resolution order
# use real domain, not var:
# $domain !== domain.com
server_name $domain;
disable_symlinks if_not_owner from=/home/$id/projects/$folder/www;
server_name_in_redirect off;
# access_log /var/log/nginx/example.com.nginx.access.log main;
# [ debug | info | notice | warn | error | crit ]
# error_log /var/log/nginx/error.log info;
index index.php;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
client_max_body_size 1024M;
client_body_buffer_size 4M;
# some times throw mime error in IE
add_header X-Content-Type-Options nosniff;
root /home/$id/projects/$folder/www;
# timeouts
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
location ~ ^/bitrix/modules {
deny all;
}
location / {
try_files $uri $uri/ @bitrix;
}
location ~ \.php$ {
try_files $uri @bitrix;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass $socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# set mbstring.func_overload = 2 in php.ini
# this params not reload in config after php >=5.4
# fastcgi_param PHP_VALUE "mbstring.func_overload = 2";
# fastcgi_param PHP_VALUE "mbstring.internal_encoding = UTF-8";
# include standart
include fastcgi_params;
# show real name not regexp
fastcgi_param SERVER_NAME $host;
fastcgi_read_timeout 300;
}
location @bitrix {
fastcgi_pass $socket;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/bitrix/urlrewrite.php;
}
location ~* /bitrix/admin.+\.php$ {
try_files $uri @bitrixadm;
fastcgi_pass $socket;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
location @bitrixadm {
fastcgi_pass $socket;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/bitrix/admin/404.php;
}
location ^~ /upload/ {
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php last;
}
types {
text/plain text/plain php php3 php4 php5 php6 phtml pl asp aspx cgi dll exe ico shtm shtml fcg fcgi fpl asmx pht;
# ie ? not shown ? why ?
image/svg+xml svg svgz;
}
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar)$ {
access_log off;
expires max;
error_page 404 = /404.html; #не забываем создать страницу
}
location ~ (/\.ht|/bitrix/modules|/upload/support/not_image|/bitrix/php_interface) {
deny all;
}
location ~ /.svn/ {
deny all;
}
# development resource in dieranet.org
location ~ /(\.idea|\.ht|\.deprecated|\.git|\.dumps) {
deny all;
}
}
@kostalakosta
Copy link

Thanks! Work on Bitrix 17.5.7 to.

@adminnu
Copy link

adminnu commented Oct 19, 2018

Наш вариант конфигурационного файла:
1С-Битрикс + Nginx + php-fpm + композитный сайт

@pleaz
Copy link

pleaz commented Nov 28, 2018

Наш вариант конфигурационного файла:
1С-Битрикс + Nginx + php-fpm + композитный сайт

@adminnu ваш вариант не полный и не доработанный

@paskal
Copy link

paskal commented Apr 21, 2021

proxy_set_header doesn't work with fastcgi and can be safely removed AFAIK. Same for these:

  proxy_connect_timeout 600;
  proxy_send_timeout 600;
  proxy_read_timeout 600;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment