Nginx虚拟目录配置文件(包含PHP配置与重写)

来源:互联网 发布:提取伴奏的软件 编辑:程序博客网 时间:2024/06/04 21:43
server {    listen       80;    server_name  www.xxxx.com;    root   /www/xxxx;    location / {        index  index.html index.htm index.php;        if ( !-e $request_filename ){                                rewrite ^/(.*)$ /index.php last;                                break;                }    }location ~ .*\.(php|php5)?${try_files $uri =404;fastcgi_pass  127.0.0.1:9000;fastcgi_index index.php;include /etc/nginx/fastcgi.conf;fastcgi_split_path_info ^(.+\.php)(.*)$;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param PATH_INFO $fastcgi_path_info;fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;include fastcgi_params;}}

补充:

以上的配置,是给PHP配置PATH_INFO路由使用的,之前没有进行解析,并且以上配置有不少的缺点

先来说说index,index是配置默认访问的页面。我将它配置在location下面了,如果我再配置多一个location,下面同样也有index。由于location是平级的,将会导致index指令重复,应该将其放到server下

接下来,看看if指令。if指令是rewrite模块中的一部分,只能应用于rewrite语句当中。上面的例子,没有问题,也可以使用try_files命令去替代




0 0
原创粉丝点击