0

更新!!!:这里讨论的问题完全由这个主题解决:

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”。

4

2 回答 2

0

答案 2:

替换下面的conf行

    if (!-e $request_filename) {
        rewrite  ^/(.*)$   /index.php?q=$1  last;
        break;
    }

    location / {
        proxy_pass http://backend;
    }

有了这个:

location / {
    root   /path/to/drupal;
    index  index.php index.html;

    if (!-e $request_filename) {
        rewrite  ^/(.*)$  /index.php?q=$1  last;
        break;
    }

}

这是有用的链接:

http://hostingfu.com/article/running-drupal-with-clean-url-on-nginx-or-lighttpd#toc-nginx

快速信息:

如果drupal安装在根目录下,

if (!-e $request_filename) {
rewrite  ^/(.*)$   /index.php?q=$1  last;
 break;
}

如果 drupal 在子目录中,

if ($request_uri ~* ^.*/.*$) {
rewrite ^/(\w*)/(.*)$  /$1/index.php?q=$2 last;
break;
}
于 2011-06-13T09:11:48.477 回答
0

以这种方式配置 nginx: https ://github.com/stanislaw/config_files/blob/master/nginx.conf导致 Drupal 出现以下行为:如果站点处于维护模式,一切正常。浏览所有非 root url(以管理员身份登录)是可以的。但是,如果我将站点设置为在线模式,那么我再次开始出现“页面未正确重定向”(第一个 UPD)。

然后我在全新的 drupal 安装上测试了相同的配置——它在离线和在线模式下都工作。导航到所有 clean_urls 工作。

我认为该配置确实有效!但是我尝试部署的站点包含许多模块,这可能会导致此类不正确的重定向。

我最终在我的网站的 vhosts 部分中获得了干净的 url,将这个问题留到了未来。我目前的配置与 github 上的配置非常相似(参见链接),但它有 clean_urls 部分的注释(我现在使用 'location /' 而不是 'location ~ .php')。

无论如何,我将非常感谢对我当前配置的任何建议和评论(请参阅 github 上的 nginx.conf - 上面的链接)。

UPD:这里是关于 nginx 的 drupal 组的相关帖子: http ://groups.drupal.org/node/155564

于 2011-06-14T10:10:34.620 回答