0

これは、Drupalのnginx構成のスニペットです。

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をキャッチし、「ページが見つかりません」エラーが発生しないように適切に書き換えるにはどうすればよいですか?

4

2 に答える 2

1

lastロケーションマッチの別のラウンドをトリガーするには、追加する必要があります。これがないと、リクエストは/stagingロケーションブロックにトラップされます。

location /staging {
    rewrite ^/staging/(.*)$ /index.php?q=$1 last;
}
于 2013-04-18T21:25:22.707 に答える
0

これを試して、Webサイトの構成を確認してください。

Nginx構成が機能する例を次に示し ます。機能しない場合は、エラーログを投稿してください。

于 2013-04-18T14:40:10.973 に答える