这是我为 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 并正确重写它们,以免出现“找不到页面”错误?