2013-03-26 17 views
0

這是我的nginx的配置爲Drupal一個片段:爲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; 
    } 

} 

這工作完全正常用這樣的

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

網址,直到包含一個硬編碼的網址「/ staging /」被處理。例如:

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

這顯示「找不到網頁」頁。我試圖加入這一行:

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

但是這似乎並沒有在所有的工作。如何使用「/ staging /」捕獲所有URL並正確重寫,因此我沒有收到「Page not found」錯誤?

+0

你的意思是這個「/ staging」部分的網址不能被Drupal菜單的URL處理程序識別嗎? – regilero 2013-03-27 11:19:37

回答

1

您需要添加last來觸發另一輪位置匹配。沒有它,你的請求被困在/staging位置塊。

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