大家都知道Drupal在apache環境下使用簡潔鏈接是件很輕松的事,因為官方已經把寫好的.htaccess文件附在源代碼里,一般在配置里直接就可以打開了。但在Nginx下卻沒有那么簡單,但不用擔心,實事上並不怎么復雜。簡單來說,其實就是添加一段很短的代碼就可以了,你也沒必要理解原理。
Nginx開啟方法
在你的nginx配置文件下添加(紅色部分):
server { listen 80; server_name mentry.cn; #server_name end index index.html index.htm index.php; #index end root /home/wwwroot/mentry.cn/web$subdomain; location / { try_files $uri $uri/ /index.php; } }
實操例子
假如我的網站使用了虛擬主機技術,那么只需要虛擬主機配置文件中直接添加就可以了。例如我的是使用AMH4.0套件(LNMP),那么在/usr/local/nginx/conf/vhost/下有類似“mentry.net.conf”虛擬主機配置文件,打開后,添加紅色代碼就可以了。
server
{
listen 80;
server_name mentry.net; #server_name end
index index.html index.htm index.php; #index end
set $subdomain '';
root /home/wwwroot/mentry.net/web$subdomain;
include rewrite/amh.conf; #rewrite end
#error_page
error_page 400 /ErrorPages/400.html;
error_page 403 /ErrorPages/403.html;
error_page 404 /ErrorPages/404.html;
error_page 502 /ErrorPages/502.html;
location ~ /ErrorPages/(400|401|403|404|405|502|503)\.html$
{
root /home/wwwroot/mentry.cn/web;
}
location ~ .*\.php$
{
fastcgi_pass unix:/tmp/php-cgi-mentry.cn.sock;
fastcgi_index index.php;
include fcgi-host.conf;
fastcgi_param DOCUMENT_ROOT /web$subdomain;
fastcgi_param SCRIPT_FILENAME /web$subdomain$fastcgi_script_name;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp3|wma)$
{
expires 30d;
}
location ~ .*\.(js|css)$
{
expires 12h;
}
access_log off; #access_log end
error_log /dev/null; #error_log end
location / {
try_files $uri $uri/ /index.php;
}
}