【问题标题】:nginx rewrite for Drupal and bad URLsnginx 重写 Drupal 和错误的 URL
【发布时间】:2013-04-19 05:25:22
【问题描述】:

这是我的 Drupal 的 nginx 配置的 sn-p:

server {
    listen       80;
    server_name  _;
    root /home/testing/public_html/staging;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location = /backup {
        deny all;
    }

    location ~* \.(txt|log)$ {
        deny all;
    }

    location / {
        try_files $uri @rewrite;
    }

    location @rewrite {
        rewrite ^/(.*)$ /index.php?q=$1;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
        fastcgi_pass unix:/tmp/php-fpm.sock;
    }

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

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        rewrite ^/staging/(.*)$ /$1;
        expires max;
        log_not_found off;
    }

}

这对像这样的 URL 非常有效

http://www.testing.com/this/page
http://www.testing.com/that/page

直到处理包含“/staging/”的硬编码 URL。示例:

http://www.testing.com/staging/this/page

这会显示“找不到页面”页面。我尝试添加这一行:

location /staging {
    rewrite ^/staging/(.*)$ /index.php?q=$1;
}

但这似乎根本不起作用。如何捕获所有带有“/staging/”的 URL 并正确重写它们,以免出现“找不到页面”错误?

【问题讨论】:

  • 你的意思是这个“/staging”部分的url不能被Drupal菜单url处理程序识别吗?

标签: drupal nginx rewrite


【解决方案1】:

您需要添加last 以触发另一轮位置匹配。没有它,您的请求将被困在/staging 位置块中。

location /staging {
    rewrite ^/staging/(.*)$ /index.php?q=$1 last;
}

【讨论】:

    【解决方案2】:

    通过尝试这个来检查您的网站配置。

    Here is an example of working Nginx configuration 如果它不起作用,请发布您的错误日志。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多