![将 Drupal Boost .htaccess 转换为 Nginx](https://linux22.com/image/625461/%E5%B0%86%20Drupal%20Boost%20.htaccess%20%E8%BD%AC%E6%8D%A2%E4%B8%BA%20Nginx.png)
我正在尝试安装促进模块与 nginx 配合使用。众所周知,Boost 不会像 Apache 那样生成 nginx 指令。
Boost 对 Apache 的 .htaccess 有以下指令:
### BOOST START ###
# Allow for alt paths to be set via htaccess rules; allows for cached variants (future mobile support)
RewriteRule .* - [E=boostpath:normal]
# Caching for anonymous users
# Skip boost IF not get request OR uri has wrong dir OR cookie is set OR request came from this server OR https request
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD)$ [OR]
RewriteCond %{REQUEST_URI} (^/(admin|cache|misc|modules|sites|system|openid|themes|node/add|comment/reply))|(/(edit|user|user/(login|password|register))$) [OR]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_COOKIE} DRUPAL_UID [OR]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [S=3]
# GZIP
RewriteCond %{HTTP:Accept-encoding} !gzip
RewriteRule .* - [S=1]
RewriteCond %{DOCUMENT_ROOT}/cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html -s
RewriteRule .* cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html,E=no-gzip:1]
# NORMAL
RewriteCond %{DOCUMENT_ROOT}/cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html -s
RewriteRule .* cache/%{ENV:boostpath}/%{HTTP_HOST}%{REQUEST_URI}_%{QUERY_STRING}\.html [L,T=text/html]
### BOOST END ###
我尝试使用这个将上面的代码转换为 nginx地点毫无作用。以下是转换后的代码,但不起作用:
# nginx configuration
location / {
rewrite ^(.*)$ /cache/$env_boostpath/$http_host$request_uri_$query_string\.html;
rewrite ^(.*)$ /cache/$env_boostpath/$http_host$request_uri_$query_string\.html;
}
有人能帮帮我吗?
谢谢
答案1
nginx 不是 apache。try_files
对于这种事情,您应该使用 ,而不是重写。
例如,这被撕掉了做得很好Drupal nginx 配置示例:
try_files /cache/normal/$host${uri}_${args}.html /cache/perm/$host${uri}_.css /cache/perm/$host${uri}_.js /cache/$host/0$uri.html /cache/$host/0${uri}/index.html @drupal;