更新!!!:这里讨论的问题完全由这个主题解决:
http://groups.drupal.org/node/155564
并通过详细探索:
Nginx 和 Drupal 大师的 Nginx 配置 - António PP Almeida (Perusio)。
https://github.com/perusio/drupal-with-nginx
无法解决以下问题:我有 FreeBSD、Apache 2.2、PHP(没有 FastCGI!)作为 apache 模块、nginx 0.8.5.4。
我正在尝试将启用了 boost 和 image_cache 的 Drupal 门户移动到个人 VPS 服务器。
我的目标是在 nginx 中重写 clean_url 并纠正 boost & image_cache 规则。
请帮忙!我知道我当前的 nginx 配置出了点问题。一整天都被它剪掉了。
这是 nginx.conf (现在只有 / 路由有效):
用户 www www; worker_processes 1; 事件{ worker_connections 1024; } http { 包括 mime.types; default_type 应用程序/八位字节流; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx-access.log main; reset_timedout_connection 开启; 发送文件; aio 发送文件; tcp_nopush 开启; #keepalive_timeout 0; keepalive_timeout 65; gzip打开; 上游后端{ # 阿帕奇服务器 服务器 77.72.19.19:81; } 服务器 { 听 77.72.19.19:80 默认 accept_filter=httpready; server_name 77.72.19.19; proxy_set_header 主机 $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; gzip打开; gzip_static 开启; gzip_proxied 任何; gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript; 设置 $myroot /usr/local/www/apache22/data/alfa; 根 $myroot; 位置〜^\。{ 全部否认; } 设置 $boost ""; 设置 $boost_query "_"; if ( $request_method = GET ) { 设置 $boost G; } if ($http_cookie !~ "DRUPAL_UID") { 设置 $boost "${boost}D"; } if ($query_string = "") { 设置 $boost "${boost}Q"; } if ( -f $myroot/cache/normal/$http_host$request_uri$boost_query$query_string.html ) { 设置 $boost "${boost}F"; } if ($boost = GDQF){ 重写 ^.*$ /cache/normal/$http_host/$request_uri$boost_query$query_string.html 中断; } if ( -f $myroot/cache/perm/$http_host$request_uri$boost_query$query_string.css ) { 设置 $boost "${boost}F"; } if ($boost = GDQF){ 重写 ^.*$ /cache/perm/$http_host/$request_uri$boost_query$query_string.css 中断; } if ( -f $myroot/cache/perm/$http_host$request_uri$boost_query$query_string.js ) { 设置 $boost "${boost}F"; } if ($boost = GDQF){ 重写 ^.*$ /cache/perm/$http_host/$request_uri$boost_query$query_string.js 中断; } 位置 ~ ^/sites/.*/files/imagecache/ { #try_files $uri @rewrite; error_page 404 = /; } 位置 ~* \.(txt|jpg|jpeg|css|js|gif|png|bmp|flv|pdf|ps|doc|mp3|wmv|wma|wav|ogg|mpg|mpeg|mpg4|htm|zip| bz2|rar|xls|docx|avi|djvu|mp4|rtf|ico)$ { 最大过期; add_header 变化接受编码; if (-f $request_filename) { 休息; } if (!-f $request_filename) { proxy_pass "http://backend"; 休息; } } 位置 ~* \.(html(.gz)?|xml)$ { add_header 缓存控制无缓存,无存储,必须验证; 根 $myroot; if (-f $request_filename) { 休息; } if (!-f $request_filename) { proxy_pass "http://backend"; 休息; } } if (!-e $request_filename) { 最后重写 ^/(.*)$ /index.php?q=$1; 休息; } 地点 / { proxy_pass http://backend; } } }
UPD:有了这个 nginx.conf 我有工作 /. 任何其他页面都会给我:“页面没有正确重定向”。谁能解释一下评估位置规则的顺序?如果是“break”——当 nginx 遇到这一行时,它接下来会做什么。我真的尝试了大约 20 个 nginx 配置示例。我不想要更多链接,我更希望有人真正了解 nginx.conf 中发生的事情的答案。
UPD2:如果我更换
if (!-e $request_filename) { 最后重写 ^/(.*)$ /index.php?q=$1; 休息; }
和:
try_files $uri $uri/ @drupal; 位置@drupal { 最后重写 ^ /index.php?q=$uri; # 对于 Drupal 6 }
然后所有非根页面都给我 404“在此服务器上找不到请求的 URL”。