一堆Nginx + PHP-FPM中的Bitrix,设置了CNC,以及通过nginx反馈的复合缓存。 修改后的配置

目的:为Bitrix-cms提供与Nginx + PHP-FPM结合使用的Nginx虚拟服务器配置。 除其他事项外,它还适用于Nginx + Apache2捆绑包,并进行了少量修改。

目标受众:服务器管理员,高级站点管理员,程序员。

关于此主题的文章足够多,但如果您看的不是官方的文章,则通常包含错误,如果不建议在Nginx中使用,则官方的文章也很多。 我希望发布此配置后,Nginx + PHP-FPM捆绑包将变得更加严肃。

这是复合缓存通过nginx起作用的官方配置。

我将显示复合缓存返回文件的实现。 通常,通过类推返回memcached。 在文件缓存返回配置中,我计算了11个ifs,通过在地图上重做来消除了这些ifs。

对于那些只需要一堆Nginx + PHP-FPM而又不需要通过Nginx返回复合缓存的人,我将从CNC的简化版本开始。 可以理解,服务器部分已经配置好,带有域名并提交给php-fpm。

location / { try_files $uri $uri/ /bitrix/urlrewrite.php$is_args$args; } 

当我看着那些画布时,这并不奇怪,这足以使Bitrix正常工作。 如果您需要从index.php和index.html重定向到no,那么您仍然需要添加以下行:

 if ($request_uri ~ ^(.*)/index.(html|php)) { return 301 $1/$is_args$args; } 

不幸的是,如果没有值得的替代。 但是,这条线不会产生问题。

简约配置示例
 server { listen 80; server_name site.ru; root /var/www/site.ru/; index index.php; location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; } if ($request_uri ~ ^(.*)/index.(html|php)) { return 301 $1/$is_args$args; } location / { try_files $uri $uri/ /bitrix/urlrewrite.php$is_args$args; } location ~* @.*\.html$ { internal; } } 


我要强调的是,这是一种简约的配置,没有用于静态,压缩的规则,在这里,我仅介绍了直接访问中的复合缓存文件。 通过nginx直接访问覆盖某些地方的配置非常单独。 我有可能适合某人的套件。 但是您需要谨慎使用它。 请记住,将位置数据输入到您的配置中可能会导致站点无法运行或其部分功能。

配置的一部分阻止对文件的访问,该文件仅在从PHP访问时才应该可用
 location ~ \.php$ { location ~* /\.\./ { internal; } location ~ /\.[^/]+$ { internal; } location ~* ^/upload/1c_[^/]+/ { internal; } location ~* ^/(bitrix/(cache|images|tmp)|upload)/ { internal; } location ~* ^/bitrix/(footer|header|license_key)\.php$ { internal; } location ~* ^/(bitrix|local)/components/(.*)/(.*)/(class|component)\.php$ { internal; } location ~* ^/(bitrix|local)/(backup|blocks|bx_cloud_upload|local_cache|module|modules|managed_cache|php_interface|public|stack_cache)/ { internal; } include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; } location ~* \.(hg|svn|git|bzr)$ { internal; } location ~* /\.\./ { internal; } location ~* @.*\.html$ { internal; } location / { location ~* ^/(bitrix|local)/(backup|blocks|bx_cloud_upload|local_cache|module|modules|managed_cache|php_interface|public|services|stack_cache)/ { internal; } location ~ /\.[^/]+$ { internal; } location ~* ^/upload/1c_[^/]+/ { internal; } try_files $uri $uri/ /bitrix/urlrewrite.php$is_args$args; } 


当然还有静态文件的位置示例

 location ~* \.(jpg|jpeg|png|tiff|gif|webp|xml|html|yml|ogg|ogv|svg|svgz|eot|otf|woff|woff2|mp4|ttf|rss|atom|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|rtf|pdf|txt|js|css|bmp|pnm|pbm|ppm)$ { access_log off; expires 97d; } 

现在,让我们继续进行组合的配置,以通过nginx返回缓存文件。 首先,有必要确定是否有可能将复合缓存提供给该请求,或者是否需要通过php发送复合缓存以进行处理。 为此,在Nginx的http部分中,添加一些映射以及一些指令:

 modern_browser_value "modern"; modern_browser msie 10.0; modern_browser unlisted; map "$cookie_BITRIX_SM_LOGIN:$cookie_BITRIX_SM_UIDH:$cookie_BITRIX_SM_CC" $storedAuth { default ""; "~*:*:Y" ""; "~*:*:*" 1; "~*:*:" 1; } map "$request_method:$http_bx_action_type:$cookie_BITRIX_SM_NCC:$http_x_forwarded_scheme:$modern_browser:$storedAuth" $usecache { default "1"; "~GET:::*https*" "1"; "~GET:::*:*:" ""; } 

接下来,我们直接在服务器部分中编写

 set $i "index@"; location / { try_files /bitrix/html_pages/$host$uri$i${args}.html$usecache /bitrix/html_pages/$host$uri$i${args}=.html$usecache /bitrix/html_pages/$host$uri/$i${args}.html$usecache /bitrix/html_pages/$host$uri/$i${args}=.html$usecache $uri $uri/ /bitrix/urlrewrite.php$is_args$args; } 

好吧,要了解服务器部分的最低配置看起来如何

通过nginx返回文件复合缓存的简约配置示例
 server { listen 80; server_name site.ru; root /var/www/site.ru/; index index.php; location ~ \.php$ { include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_intercept_errors on; } if ($request_uri ~ ^(.*)/index.(html|php)) { return 301 $1/$is_args$args; } set $i "index@"; location / { try_files /bitrix/html_pages/$host$uri$i${args}.html$usecache /bitrix/html_pages/$host$uri$i${args}=.html$usecache /bitrix/html_pages/$host$uri/$i${args}.html$usecache /bitrix/html_pages/$host$uri/$i${args}=.html$usecache $uri $uri/ /bitrix/urlrewrite.php$is_args$args; } location ~* @.*\.html$ { internal; } } 

我将很高兴收到有关此配置的问题和建议,也很高兴看到您的成就。

Source: https://habr.com/ru/post/zh-CN438604/


All Articles