我有一個使用子目錄的站點,並且當前只有當URL中添加了斜線時才起作用(「http://www.domain.com/dir/」)。當沒有結尾的斜槓時,我得到「無法連接到服務器domain.com:8080」(8080是Nginx設置的監聽端口)。Nginx不喜歡重寫
我嘗試添加重寫建議here(和here),但它導致整個虛擬主機的「無法連接」錯誤。
是否有另一種方法來添加我可以嘗試的尾部斜線?或者,有沒有一種方法可以將它配置爲將URL看作目錄(並因此查找索引文件),而不管是否存在尾部斜槓?
編輯
Nginx.conf:
user www-data;
worker_processes 4;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
map $scheme $fastcgi_https { ## Detect when HTTPS is used
default off;
https on;
}
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
服務器塊:
server {
listen 8080;
server_name domain.com www.domain.com;
include www.inc;
root /var/vhosts/domain/current/frontend/;
include php.inc;
}
Php.inc:
index index.php;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param ENVIRONMENT production;
fastcgi_param HTTPS $fastcgi_https;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#fastcgi_intercept_errors on;
fastcgi_connect_timeout 10;
fastcgi_send_timeout 15;
fastcgi_read_timeout 120;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
include fastcgi_params;
}
www.inc:
if ($host ~ ^([^\.]+\.com)) {
rewrite ^/(.*)$ http://www.$host/$1 permanent;
}
請添加服務器{} config其中重寫不起作用。 – 2011-05-03 20:18:08
已添加,以及包含。我只是想 - 是www重寫問題?如果是這樣,我可以修改它在那裏添加斜線,但它是否適用於已經包含www的URL?有沒有更好的方法來修改它?我需要www檢查。 – Shauna 2011-05-03 20:31:08