您在這裡

ask help for clean URL ? anyone can help me out ???

quinnlam's 的頭像
quinnlam 在 2011-01-18 (二) 18:12 發表

I installed nginx + php + drupal 7 at my windows 7 for test . But i cannot turn on drupal 7 clean url , i search answer from many webiste but still cannot turn clean url on , So please help me out !!!!!!!

the following is my nginx rewrite :

location / {
root E:\www-test\mywwwroot\drupal-7.0;
index index.php index.html index.htm;

# the main drupal app
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}
}

location ~ \.php$ {
root E:\www-test\mywwwroot\drupal-7.0;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:\www-test\mywwwroot\drupal-7.0$fastcgi_script_name;
include fastcgi_params;
}

多谢 notaBlueScreen 你的指教, 我想问一问,你说的哪个rewrite是要加入到NGINX的conf文件内吗? 还是在什么地方? 可否贴一个完整的出来给我看下,小弟已对这个NGINX drupal 7 的 rewrite烦了两天,网上好多方案都是在NGINX的conf文件内加一些规则,但我试过都没用,无论是将druapl安装在子文件夹还是主目录,暂时我是放在子目录的。。 我网站的主目录是 E:\www-test\mywwwroot 。 drupal放在 E:\www-test\mywwwroot\drupal-7.0 内。。。

我贴上了nginx的conf文件, 我的网站主目录是 E:\www-test\mywwwroot\ , 我将我的drupal7放在 E:\www-test\mywwwroot\drupal-7.0 内。。

localhost:8087是直接读取网站主目录E:\www-test\mywwwroot\ 的, 我再新开了个网站localhost:8077,并将其的主目录设为E:\www-test\mywwwroot\drupal-7.0

我在网上找到,如drupal放在主或次目录的话,Nginx的rewrite应写成如下:
If Drupal install in the root directory,
?
1
2
3
4 if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
break;
}
if drupal in a subdirectory,
?
1
2
3
4 if ($request_uri ~* ^.*/.*$) {
rewrite ^/(\w*)/(.*)$ /$1/index.php?q=$2 last;
break;
}

以下是我的Nginx的conf文件,请帮手看一看,如要变的话,请指出哪部分,并要变成什么样。本人刚学nginx,对这些所谓的rewrite并不是太了解,请帮手,多谢。。。

#user nobody;
worker_processes 1;

error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;

server {
listen 8078;
server_name localhost;

if ($request_uri ~* ^.*/.*$) {
rewrite ^/(\w*)/(.*)$ /$1/index.php?q=$2 last;
break;
}

autoindex on;
######### 当网站没有默认文件时,打开域名可以看到文件目录结构

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root E:\www-test\mywwwroot;
index index.php index.html index.htm;
# 实现伪静态的地方,如果不是物理文件,则使用下面的定义

# last 就表示这是最后一条处理命令,如果匹配,下面的不管了

if ($request_uri ~* ^.*/.*$) {
rewrite ^/(\w*)/(.*)$ /$1/index.php?q=$2 last;
break;
}

}

#error_page 404 /index.php;
# 404 交给 index.php 处理
# error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root E:\www-test\mywwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:\www-test\mywwwroot$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

############################################ ############################################

server {
client_max_body_size 25m;
client_body_buffer_size 128k;
listen 8077;
server_name localhost;

root E:\www-test\mywwwroot\drupal-7.0;

#upload_max_file_size 25M;
charset utf-8;
# access_log /var/www/www.soa.tw/logs/access.log;
# error_log /var/www/www.soa.tw/logs/error.log;

location = / {
index index.php;
}

location / {
index index.php index.html;

if (!-f $request_filename) {
rewrite ^(.*)$ /index.php?q=$1 last;
break;
}

if (!-d $request_filename) {
rewrite ^(.*)$ /index.php?q=$1 last;
break;
}

}

error_page 404 /index.php;

# serve static files directly
location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico)$ {
access_log off;
expires 30d;
break;
}

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

location ~ \.php$ {
root E:\www-test\mywwwroot\drupal-7.0;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:\www-test\mywwwroot\drupal-7.0$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}

}

}

我沒測試,但應該可行
留意 {} 有沒有多了或少了的問題


#user nobody;
worker_processes 1;

error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;

server {
listen 8078;
server_name localhost;

autoindex on;
######### 当网站没有默认文件时,打开域名可以看到文件目录结构

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root E:\www-test\mywwwroot;
index index.php index.html index.htm;
# 实现伪静态的地方,如果不是物理文件,则使用下面的定义

# last 就表示这是最后一条处理命令,如果匹配,下面的不管了

if ($request_uri ~* ^.*/.*$) {
rewrite ^/(\w*)/(.*)$ /$1/index.php?q=$2 last;
break;
}

}

location /drupal-7.0/ {
index index.php index.html;

if (!-e $request_filename) {
rewrite ^ /drupal-7.0/index.php last;
break;
}

}

#error_page 404 /index.php;
# 404 交给 index.php 处理
# error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root E:\www-test\mywwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:\www-test\mywwwroot$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}

}

---
notaBlueScreen

這樣呢


#user nobody;
worker_processes 1;

error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

gzip on;

server {
listen 8078;
server_name localhost;
root E:\www-test\mywwwroot;

autoindex on;

location /drupal-7.0/ {
index index.php index.html;

if (-f $request_filename) {
expires 30d;
break;
}

if (!-e $request_filename) {
rewrite ^ /drupal-7.0/index.php last;
break;
}

}

#error_page 404 /index.php;
# 404 交给 index.php 处理
# error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:\www-test\mywwwroot$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}

}

---
notaBlueScreen

图与CSS可看到了,但还是不能启动CLEAN URL,按完run the clean url test后,都是没反应,选项出不来,请问你有没试过在WINDOWS上试过用nginx加drupal起动clean url,因我见网上的方法我都用过了,但都不能,不知是否它们是在LINUX上试,不过按我的理解,应与系统没关的。。。

error.log:

2011/01/19 19:00:17 [error] 3464#4368: *15 CreateFile() "E:\www-test\mywwwroot\drupal-7.0/admin/config/search/clean-urls/check" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /admin/config/search/clean-urls/check HTTP/1.0", host: "localhost:8077"
2011/01/19 19:00:58 [error] 4876#3008: *4 CreateFile() "E:\www-test\mywwwroot\drupal-7.0/admin/config/search/clean-urls/check" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /admin/config/search/clean-urls/check HTTP/1.0", host: "localhost:8077"
2011/01/19 19:01:33 [error] 4876#3008: *8 CreateFile() "E:\www-test\mywwwroot\drupal-7.0/admin/config/search/clean-urls/check" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /admin/config/search/clean-urls/check HTTP/1.0", host: "localhost:8077"
2011/01/19 19:02:04 [error] 4876#3008: *11 CreateFile() "E:\www-test\mywwwroot\drupal-7.0/admin/config/search/clean-urls/check" failed (3: The system cannot find the path specified), client: 127.0.0.1, server: localhost, request: "GET /admin/config/search/clean-urls/check HTTP/1.0", host: "localhost:8077"
2011/01/19 20:53:21 [error] 7724#1852: *1 CreateFile() "E:\www-test\mywwwroot/favicon.ico" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost:8078"

access.log:

127.0.0.1 - - [19/Jan/2011:21:10:32 +0800] "GET /drupal-7.0/themes/seven/style.css?lf44wv HTTP/1.1" 200 18314 "http://localhost:8078/drupal-7.0/?q=admin%2Fconfig%2Fsearch%2Fclean-urls..." "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Tablet PC 2.0)"
127.0.0.1 - - [19/Jan/2011:21:10:32 +0800] "GET /drupal-7.0/themes/seven/ie.css?lf44wv HTTP/1.1" 200 360 "http://localhost:8078/drupal-7.0/?q=admin%2Fconfig%2Fsearch%2Fclean-urls..." "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Tablet PC 2.0)"
127.0.0.1 - - [19/Jan/2011:21:10:32 +0800] "GET /drupal-7.0/modules/system/system.js?lf44wv HTTP/1.1" 200 4941 "http://localhost:8078/drupal-7.0/?q=admin%2Fconfig%2Fsearch%2Fclean-urls..." "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Tablet PC 2.0)"
127.0.0.1 - - [19/Jan/2011:21:10:32 +0800] "GET /drupal-7.0/modules/overlay/overlay-child.js?v=1.0 HTTP/1.1" 200 6688 "http://localhost:8078/drupal-7.0/?q=admin%2Fconfig%2Fsearch%2Fclean-urls..." "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Tablet PC 2.0)"
127.0.0.1 - - [19/Jan/2011:21:10:32 +0800] "GET /drupal-7.0/themes/seven/images/buttons.png HTTP/1.1" 200 786 "http://localhost:8078/drupal-7.0/?q=admin%2Fconfig%2Fsearch%2Fclean-urls..." "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Tablet PC 2.0)"
127.0.0.1 - - [19/Jan/2011:21:10:33 +0800] "GET /drupal-7.0/modules/overlay/images/close.png HTTP/1.1" 200 344 "http://localhost:8078/drupal-7.0/?q=admin%2Fconfig%2Fsearch%2Fclean-urls..." "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Tablet PC 2.0)"
127.0.0.1 - - [19/Jan/2011:21:10:33 +0800] "GET /drupal-7.0/modules/shortcut/shortcut.png HTTP/1.1" 200 432 "http://localhost:8078/drupal-7.0/?q=admin%2Fconfig%2Fsearch%2Fclean-urls..." "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Tablet PC 2.0)"
127.0.0.1 - - [19/Jan/2011:21:11:05 +0800] "GET /drupal-7.0/admin/config/search/clean-urls/check HTTP/1.0" 499 0 "-" "Drupal (+http://drupal.org/)"
127.0.0.1 - - [19/Jan/2011:21:11:05 +0800] "POST /drupal-7.0/?q=admin%2Fconfig%2Fsearch%2Fclean-urls&render=overlay&render=overlay HTTP/1.1" 302 5 "http://localhost:8078/drupal-7.0/?q=admin%2Fconfig%2Fsearch%2Fclean-urls..." "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Tablet PC 2.0)"
127.0.0.1 - - [19/Jan/2011:21:11:35 +0800] "GET /drupal-7.0/admin/config/search/clean-urls/check HTTP/1.0" 499 0 "-" "Drupal (+http://drupal.org/)"
127.0.0.1 - - [19/Jan/2011:21:11:35 +0800] "GET /drupal-7.0/?q=admin/config/search/clean-urls&render=overlay HTTP/1.1" 200 2589 "http://localhost:8078/drupal-7.0/?q=admin%2Fconfig%2Fsearch%2Fclean-urls..." "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E; Tablet PC 2.0)"

可以啊,幾乎沒有不同,也沒有多餘設定,就是純粹地下載


#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

root C:/w/www;

location / {
index index index.html index.htm index.php;
}
location /drupal-7.0/ {
index index index.html index.htm index.php;

if (-f $request_filename) {
expires 30d;
break;
}

if (!-e $request_filename) {
rewrite ^ /drupal-7.0/index.php last;
break;
}
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME C:/w/www$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}

# HTTPS server
#
#server {
# listen 443;
# server_name localhost;

# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

---
notaBlueScreen

我将你的文件变成如下的这样,在我的机上,都是不能啊
我只是将root 设回我的 E:\www-test\mywwwroot

请问你可否尝试一下,按我的E:\www-test\mywwwroot在你的电脑上试一试。。。

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

root E:\www-test\mywwwroot;

location / {
index index index.html index.htm index.php;
}
location /drupal-7.0/ {
index index index.html index.htm index.php;

if (-f $request_filename) {
expires 30d;
break;
}

if (!-e $request_filename) {
rewrite ^ /drupal-7.0/index.php last;
break;
}
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:\www-test\mywwwroot$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}

# HTTPS server
#
#server {
# listen 443;
# server_name localhost;

# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_timeout 5m;

# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

我已将目录移动 C:\w\www\drupal-7.0 并用你的CONF文件,全部照抄,只是加了打开rewrite log的两句。 但一样不行。。以下是我的rewrite error log文件的内容:

另外,我试过用http://localhost/drupal-7.0/node/1 是可打开我的网页的。
我试过将我的第一个文章的URL alias设成test 接着用http://localhost/drupal-7.0/test打开,一样可行。看上去好似是rewrite成功打开一样,请给予意见。

2011/01/20 18:38:03 [error] 6728#4296: *1 directory index of "C:/w/www/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"
2011/01/20 18:38:38 [notice] 6728#4296: *8 "^" matches "/drupal-7.0/admin/config/search/clean-urls/check", client: 127.0.0.1, server: localhost, request: "GET /drupal-7.0/admin/config/search/clean-urls/check HTTP/1.0", host: "localhost"
2011/01/20 18:38:38 [notice] 6728#4296: *8 rewritten data: "/drupal-7.0/index.php", args: "", client: 127.0.0.1, server: localhost, request: "GET /drupal-7.0/admin/config/search/clean-urls/check HTTP/1.0", host: "localhost"
2011/01/20 18:39:11 [notice] 6728#4296: *11 "^" matches "/drupal-7.0/admin/config/search/clean-urls/check", client: 127.0.0.1, server: localhost, request: "GET /drupal-7.0/admin/config/search/clean-urls/check HTTP/1.0", host: "localhost"
2011/01/20 18:39:11 [notice] 6728#4296: *11 rewritten data: "/drupal-7.0/index.php", args: "", client: 127.0.0.1, server: localhost, request: "GET /drupal-7.0/admin/config/search/clean-urls/check HTTP/1.0", host: "localhost"
2011/01/20 18:39:42 [notice] 6728#4296: *14 "^" matches "/drupal-7.0/admin/config/search/clean-urls/check", client: 127.0.0.1, server: localhost, request: "GET /drupal-7.0/admin/config/search/clean-urls/check HTTP/1.0", host: "localhost"
2011/01/20 18:39:42 [notice] 6728#4296: *14 rewritten data: "/drupal-7.0/index.php", args: "", client: 127.0.0.1, server: localhost, request: "GET /drupal-7.0/admin/config/search/clean-urls/check HTTP/1.0", host: "localhost"

补充一下: 现在是可以用http://localhost:8078/drupal-7.0/test 这类方式打开网站,但是DRUPAL是没办法显示出可以起用CLEAN URL的按键的,我估计是DRUPAL问题,拿回了以前测试用的XAMMP(apache php mysql)来使用同一个DRUPAL程式,但是可以打开启动CLEAN URL的选项的,所以现在我估计问题都是集中在NGINX上吧,请帮手看看我上一个贴的REWRITE LOG,多谢你先。

我的 nginx rewrite rules

server {
...略
root /home/www/drupal;

location / {
try_files $uri $uri/ @drupal_root;
}

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

location @drupal_subdir {
rewrite ^/(\w*)/(.*)$ /$1/index.php?q=$2;
}

}

如果你的網站是在第一層目錄下
http://example.com/drupal/
try_files $uri $uri/ @drupal_root;
改成
try_files $uri $uri/ @drupal_subdir;

減少 if 判斷式對效能比較沒影響^^

你好 yelban 朋友, 哪我的 rewirete可写成这样吗?请指教。

server {
...略
root /home/www/;
#注这个网站的drupal是放在第一層目錄下
location / {
try_files $uri $uri/ @drupal_subdir;
}

location @drupal_subdir {
rewrite ^/(\w*)/(.*)$ /$1/index.php?q=$2;
}
l

}

另外一个是drupal是放在主目錄下,另一个server的 rewirte如下:

server {
...略
root /home/www/drupal;

location / {
try_files $uri $uri/ @drupal_root;
}

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

}

假設你的網址沒有子目錄
網站根目錄的檔案路徑是 /home/www
網址 http://example.com/(index.php)
drupal 的 index.php 路徑就是 /home/www/index.php
這時應該用 @drupal_root
try_files $uri $uri/ @drupal_root;

如果是網址有子目錄形式的
ex. http://example.com/another/(index.php)
實際檔案路徑是 /home/www/another(/index.php)
就要用 @drupal_subdir
try_files $uri $uri/ @drupal_subdir;

我试过将网站放在子目录,但当我用如下设定时,http://localhost:8078/drupal-7.0/ 只会列出文件,不会找到index.php

server {
listen 8078;
server_name localhost;
root E:\www-test\mywwwroot ;

error_log logs/erro-for-rewriter-8078.log notice;
rewrite_log on;

autoindex on;
######### 当网站没有默认文件时,打开域名可以看到文件目录结构

#charset koi8-r;

#access_log logs/host.access.log main;

location = / {
index index.php;
}

location / {
try_files $uri $uri/ @drupal_subdir;
}

location @drupal_subdir {
rewrite ^/(\w*)/(.*)$ /$1/index.php?q=$2;
}

你好yelban,我现在的情况是 网站主目录在E:\www-test\mywwwroot ,其下有一个 drupal-7.0的目录是放drupal的, 我的主网站的root 是设在 E:\www-test\mywwwroot , 所以如通过打开drupal-7.0并显示正常的话,以下是我的nginx conf 内的server文件, 我怕抄你部分再变来变去会出现都是不能正常打开URL CLEAN的情况,所以我先将我的 nginx conf给你看,如你要变的话,直接变好,贴上来,我全部抄上去试下,如OK的话,我再对比不同点,这样比较好吧。

server {
listen 8078;
server_name localhost;

error_log logs/erro-for-rewriter-my-main8078.log notice;
rewrite_log on;

root E:\www-test\mywwwroot ;

autoindex on;
######### 当网站没有默认文件时,打开域名可以看到文件目录结构

#charset koi8-r;

access_log logs/my-main8078.log ;

location = / {
index index.php;
}

location /drupal-7.0/ {
index index index.html index.htm index.php;

if (-f $request_filename) {
expires 30d;
break;
}

if (!-e $request_filename) {
rewrite ^ /drupal-7.0/index.php last;
break;
}
}

#error_page 404 /index.php;
# 404 交给 index.php 处理
# error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root E:\www-test\mywwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:\www-test\mywwwroot$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

你好yelban,我现在的情况是 网站主目录在E:\www-test\mywwwroot ,其下有一个 drupal-7.0的目录是放drupal的, 我的主网站的root 是设在 E:\www-test\mywwwroot , 所以如通过打开drupal-7.0并显示正常的话,以下是我的nginx conf 内的server文件, 我怕抄你部分再变来变去会出现都是不能正常打开URL CLEAN的情况,所以我先将我的 nginx conf给你看,如你要变的话,直接变好,贴上来,我全部抄上去试下,如OK的话,我再对比不同点,这样比较好吧。

server {
listen 8078;
server_name localhost;

error_log logs/erro-for-rewriter-my-main8078.log notice;
rewrite_log on;

root E:\www-test\mywwwroot ;

autoindex on;
######### 当网站没有默认文件时,打开域名可以看到文件目录结构

#charset koi8-r;

access_log logs/my-main8078.log ;

location = / {
index index.php;
}

location /drupal-7.0/ {
index index index.html index.htm index.php;

if (-f $request_filename) {
expires 30d;
break;
}

if (!-e $request_filename) {
rewrite ^ /drupal-7.0/index.php last;
break;
}
}

#error_page 404 /index.php;
# 404 交给 index.php 处理
# error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root E:\www-test\mywwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME E:\www-test\mywwwroot$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}