Drupal&Boost&ImageCache 的 nginx 配置

发布于 2024-11-15 07:02:23 字数 4828 浏览 2 评论 0原文

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

http:// /groups.drupal.org/node/155564

详细探索

并通过Nginx 和 Drupal 大师 António PP Almeida (Perusio)

Nginx 配置。 https://github.com/perusio/drupal-with-nginx


can't solve the following problem: I have FreeBSD, Apache 2.2, PHP (no FastCGI!) as apache module, nginx 0.8.5.4.

我正在尝试将启用了 boost 和 image_cache 的 Drupal 门户移动到个人 VPS 服务器。

我的目标是在 nginx 中重写 clean_url 并纠正 boost & image_cache 规则。

请帮忙!我知道我当前的 nginx 配置有问题。一整天的时间都被剪掉了。

这是 nginx.conf (现在只有 / 路由可以工作):

user www www; 
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    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 on;
    sendfile        on;
    aio sendfile;
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    upstream backend {
        # Apache server
        server 77.72.19.19:81;
    }

    server {
        listen       77.72.19.19:80 default accept_filter=httpready;
        server_name  77.72.19.19;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;

        gzip  on;
        gzip_static on;
        gzip_proxied any;

        gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        set $myroot /usr/local/www/apache22/data/alfa;
        root $myroot;

        location ~ ^\. {
            deny all;
        }

        set $boost "";
        set $boost_query "_";

        if ( $request_method = GET ) {
            set $boost G;
        }

        if ($http_cookie !~ "DRUPAL_UID") {
            set $boost "${boost}D";
        }

        if ($query_string = "") {
            set $boost "${boost}Q";
        }

        if ( -f $myroot/cache/normal/$http_host$request_uri$boost_query$query_string.html ) {
            set $boost "${boost}F";
        }

        if ($boost = GDQF){
            rewrite ^.*$ /cache/normal/$http_host/$request_uri$boost_query$query_string.html break;
        }

        if ( -f $myroot/cache/perm/$http_host$request_uri$boost_query$query_string.css ) {
            set $boost "${boost}F";
        }

        if ($boost = GDQF){
            rewrite ^.*$ /cache/perm/$http_host/$request_uri$boost_query$query_string.css break;
        }

        if ( -f $myroot/cache/perm/$http_host$request_uri$boost_query$query_string.js ) {
            set $boost "${boost}F";
        }

        if ($boost = GDQF){
            rewrite ^.*$ /cache/perm/$http_host/$request_uri$boost_query$query_string.js break;
        }

        location ~ ^/sites/.*/files/imagecache/ {
            #try_files $uri @rewrite;
            error_page 404 = /;
        }

        location ~* \.(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)$ 
        {
            expires max;
            add_header Vary Accept-Encoding;
            if (-f $request_filename) {
                break;
            }
            if (!-f $request_filename) {
                proxy_pass "http://backend";
                break;
            }
        }

        location ~* \.(html(.gz)?|xml)$ {
            add_header Cache-Control no-cache,no-store,must-validate;
            root $myroot;
            if (-f $request_filename) {
                break;
            }
            if (!-f $request_filename) {
                proxy_pass "http://backend";
                break;
            }
        }        

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

        location / {
            proxy_pass http://backend;
        } 

     }
}

UPD:有了这个 nginx.conf,我就可以工作 / 了。任何其他页面都会给我: “页面未正确重定向”。 谁能解释一下位置规则的评估顺序?如果是“break”——当 nginx 遇到这一行时,它接下来会做什么。我确实尝试了大约 20 个 nginx 配置示例。我不想再有一个链接,我更喜欢有人真正了解 nginx.conf 中发生的事情的答案。

更新2: 如果我替换

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

为:

        try_files $uri $uri/ @drupal;
        location @drupal {
            rewrite ^ /index.php?q=$uri last; # for Drupal 6
        }

那么所有非根页面都会给出 404“在此服务器上找不到请求的 URL”。

UPD!!!: Issue discussed here is completely solved by this topic:

http://groups.drupal.org/node/155564

And by detailed exploration of:

Nginx configuration by Nginx&Drupal guru - António P. P. Almeida (Perusio).

https://github.com/perusio/drupal-with-nginx


can't solve the following problem:
I have FreeBSD, Apache 2.2, PHP (no FastCGI!) as apache module, nginx 0.8.5.4.

I'm trying to move Drupal portal having boost and image_cache enabled on it to personal VPS server.

My goal is to have clean_url rewrites in nginx and correct boost & image_cache rules.

Please help! I know that something's very wrong with my current nginx config. The whole day has been cut on it.

Here is nginx.conf (Only / route works now):

user www www; 
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    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 on;
    sendfile        on;
    aio sendfile;
    tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    gzip  on;

    upstream backend {
        # Apache server
        server 77.72.19.19:81;
    }

    server {
        listen       77.72.19.19:80 default accept_filter=httpready;
        server_name  77.72.19.19;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;

        gzip  on;
        gzip_static on;
        gzip_proxied any;

        gzip_types text/plain text/html text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        set $myroot /usr/local/www/apache22/data/alfa;
        root $myroot;

        location ~ ^\. {
            deny all;
        }

        set $boost "";
        set $boost_query "_";

        if ( $request_method = GET ) {
            set $boost G;
        }

        if ($http_cookie !~ "DRUPAL_UID") {
            set $boost "${boost}D";
        }

        if ($query_string = "") {
            set $boost "${boost}Q";
        }

        if ( -f $myroot/cache/normal/$http_host$request_uri$boost_query$query_string.html ) {
            set $boost "${boost}F";
        }

        if ($boost = GDQF){
            rewrite ^.*$ /cache/normal/$http_host/$request_uri$boost_query$query_string.html break;
        }

        if ( -f $myroot/cache/perm/$http_host$request_uri$boost_query$query_string.css ) {
            set $boost "${boost}F";
        }

        if ($boost = GDQF){
            rewrite ^.*$ /cache/perm/$http_host/$request_uri$boost_query$query_string.css break;
        }

        if ( -f $myroot/cache/perm/$http_host$request_uri$boost_query$query_string.js ) {
            set $boost "${boost}F";
        }

        if ($boost = GDQF){
            rewrite ^.*$ /cache/perm/$http_host/$request_uri$boost_query$query_string.js break;
        }

        location ~ ^/sites/.*/files/imagecache/ {
            #try_files $uri @rewrite;
            error_page 404 = /;
        }

        location ~* \.(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)$ 
        {
            expires max;
            add_header Vary Accept-Encoding;
            if (-f $request_filename) {
                break;
            }
            if (!-f $request_filename) {
                proxy_pass "http://backend";
                break;
            }
        }

        location ~* \.(html(.gz)?|xml)$ {
            add_header Cache-Control no-cache,no-store,must-validate;
            root $myroot;
            if (-f $request_filename) {
                break;
            }
            if (!-f $request_filename) {
                proxy_pass "http://backend";
                break;
            }
        }        

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

        location / {
            proxy_pass http://backend;
        } 

     }
}

UPD: With this nginx.conf I have working /. And any other page gives me:
"The page isn't redirecting properly".
Who can explain me the order in which location rules are evaluated? And if it is "break" - when nginx meets this line, what it does next. I really tryed about 20 nginx config samples. I don't want one more link, I'd prefer answers of somebody, who has real understanding of what's going on in nginx.conf.

UPD2:
If I replace

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

with:

        try_files $uri $uri/ @drupal;
        location @drupal {
            rewrite ^ /index.php?q=$uri last; # for Drupal 6
        }

Then all non-root pages give me 404 "The requested URL was not found on this server".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨的味道风的声音 2024-11-22 07:02:23

答案 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;
}

Answer 2:

Replace the following lines of conf

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

    location / {
        proxy_pass http://backend;
    }

with this:

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

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

}

Here is the useful link:

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

For quick info:

If drupal install in the root directory,

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

If drupal in a subdirectory,

if ($request_uri ~* ^.*/.*$) {
rewrite ^/(\w*)/(.*)$  /$1/index.php?q=$2 last;
break;
}
晌融 2024-11-22 07:02:23

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

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

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

我最终在我的网站的虚拟主机部分中获得了干净的网址,将这个问题留到了将来。我目前的配置与 github 上的配置非常相似(请参阅链接),但它对 clean_urls 部分进行了注释(我现在使用“location /”而不是“location ~ .php”)。

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

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

Having nginx configured this way:
https://github.com/stanislaw/config_files/blob/master/nginx.conf led Drupal to following behaviour:
All worked okay, if the site was in maintenance mode. Navigating all non-root urls (signed in as admin) was ok. But if I put site to online mode, then I again began to get all there "Page isn't redirecting properly" (first UPD).

Then I tested the same configuration on fresh drupal installiation - it worked in both off- and online modes. Navigation to all clean_urls worked.

I think that config is indeed working!, but the site I'm trying to deploy contains of many modules, that can cause such improper redirects.

I ended up having clean urls in vhosts section for my site leaving this problem for the future. My present config is very similar to the one on github (see the link) but it has clean_urls section commented (I use 'location /' instead of 'location ~ .php' now).

Anyway, I would be very thankful really for any advices & comments on my current config (see nginx.conf on github - link above).

UPD: here's related post on nginx's drupal group:
http://groups.drupal.org/node/155564

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文