您的位置 首页 php

nginx无法解析PHP以及网站路径问题

一:nginx无法解析PHP文件故障

当用Nginx+php-fpm方式使用php的时候,如果访问php文件出现file not found的问题可以用如下方法解决

将root注释掉,并且修改fastcgi_param为SCRIPT_FILENAME $document_root$fastcgi_script_name;

location ~ \.php$ {

#root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

如果你默认不更改root目录地址,就需要将/scripts改为$document_root
#默认:fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;)

二:root路径不生效问题

配置文件中另加一项location配置参数,如下:

location / {
root /data/www;

index index.html index.php;
}

root path;

设置web资源路径映射;用于指明用户请求的url所对应的本地文件系统上的文档所在目录路径;可用的位置:http, server, location, if in location;

location [ = | ~ | ~* | ^~ ] uri { … }

Sets configuration depending on a request URI.

在一个server中location配置段可存在多个,用于实现从uri到文件系统的路径映射;ngnix会根据用户请求的URI来检查定义的所有location,并找出一个最佳匹配,而后应用其配置;

=:对URI做精确匹配;例如,

location = / {

}

~:对URI做正则表达式模式匹配,区分字符大小写;

~*:对URI做正则表达式模式匹配,不区分字符大小写;

^~:对URI的左半部分做匹配检查,不区分字符大小写;

不带符号:匹配起始于此uri的所有的url;

匹配优先级:=, ^~, ~/~*,不带符号;

root /vhosts/www/htdocs/

–> /vhosts/www/htdocs/index.html

server {

root /vhosts/www/htdocs/

location /admin/ {

root /webapps/app1/data/

}

}

alias path;

定义路径别名,文档映射的另一种机制;仅能用于location上下文;

注意:location中使用root指令和alias指令的意义不同;

(a) root,给定的路径对应于location中的/uri/左侧的/;

(b) alias,给定的路径对应于location中的/uri/右侧的/;

index file …;

默认资源;http, server, location;

error_page code … [=[response]] uri;

Defines the URI that will be shown for the specified errors.

try_files file … uri;

专注于运维:

文章来源:智云一二三科技

文章标题:nginx无法解析PHP以及网站路径问题

文章地址:https://www.zhihuclub.com/150272.shtml

关于作者: 智云科技

热门文章

网站地图