Nginx + Drupal 的簡單設定

Drupal 預設有使用 query string 來傳參數,例如頁數用 ?page=,所以在 try_files 也要傳 ?query_string 。

drupal.router.hk.conf

server {
listen 80;
root /var/www/drupal;
server_name     drupal.router.hk;
access_log      /var/log/nginx/drupal.router.hk_access.log;
error_log       /var/log/nginx/drupal.router.hk_error.log;
index   index.php;
autoindex       on;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* ^.+\.(jpg|jpeg|gif|png|css|zip|pdf|txt|js|flv|swf|html|htm)$        {
#
}
include php.conf;
}

php.conf

location ~ \.php {
try_files $uri =404;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  SCRIPT_FILENAME    $request_filename;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
}

圖片來源: Dries Buytaert.

發表回覆

你的電郵地址並不會被公開。 必要欄位標記為 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.