nginx配置虚拟机网站根目录

时间:2014-04-09 11:26:27   收藏:0   阅读:562

今天一个网友叫我帮他在我的vps上配置nginx虚拟机时,发现我更改虚拟机的根路径后,nginx只会执行,nginx默认的配置的根目录下的index.php,但是index.html的,却可以执行,觉得怪怪的,一时找不到方向怎么搞了,只好查看官方文档,

现在我们来看在一个典型的,简单的PHP站点中,nginx怎样为一个请求选择location来处理:
server {
    listen      80;
    server_name example.org www.example.org;
    root        /data/www;
    location / {
        index   index.html index.php;
    }
    location ~* \.(gif|jpg|png)$ {
        expires 30d;
    }
    location ~ \.php$ {
        fastcgi_pass  localhost:9000;
        fastcgi_param SCRIPT_FILENAME
                      $document_root$fastcgi_script_name;
        include       fastcgi_params;
    }
}

这是官方的文档,而我的错误就使用location 匹配php文件的那个位置的根目录没有更改过来,导致找不到文件,file not found

以后配置需要注意一下一点:

1:把root 写在server下,不要写在location下,

2:把location下的root 删除

本文出自 “Freax” 博客,请务必保留此出处http://freax.blog.51cto.com/6614733/1392466

nginx配置虚拟机网站根目录,布布扣,bubuko.com

原文:http://freax.blog.51cto.com/6614733/1392466

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!