我有一个使用子目录的站点,并且当前只有当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