2024.10.23更新
除了重新部署设置php_pathinfo以外,还可以按以下方法修改(免去删除站点重新添加的麻烦)
修改/usr/local/nginx/vhost/[yourdomain].conf
,在location
前添加一行,加入以下内容include enable-php-pathinfo.conf
新版本nginx目录下默认都有以下这几个配置文件
enable-php-pathinfo.conf
的内容如下:location ~ [^/]\.php(/|$) { fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi.conf; include pathinfo.conf; }
fastcgi.conf
的内容如下:fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REQUEST_SCHEME $scheme; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; fastcgi_param PHP_ADMIN_VALUE "open_basedir=$document_root/:/tmp/:/proc/";
pathinfo.conf
的内容如下:fastcgi_split_path_info ^(.+?\.php)(/.*)$; set $path_info $fastcgi_path_info; fastcgi_param PATH_INFO $path_info; try_files $fastcgi_script_name =404;
出事了...
今天首次安装Typecho,然后兴冲冲的准备写文 (之前忘记备份MySQL,以前的文章全被清除掉了……),点开网站打算登陆后台,然后......居然报404......
查阅Typecho Docs才发现,Typecho需要开启php pathinfo支持,而按照以前部署lnmp的经验,我习惯不开启pathinfo支持的,导致除了主页以外的页面内容全部无法访问......
然而按照Docs里的解决方法尝试修改以下两个配置文件,但是结果问题依旧......
/usr/local/nginx/nginx.conf
/usr/local/nginx/vhost/[yourdomain].conf
最后还是重新部署添加lnmp vhost,当出现"Enable PHP Pathinfo?(y/n)"时,必须输入"y",然后继续完成后面的操作,最后网站终于可以正常访问所有页面了......
以下是Typecho官网Docs的解决方案
(但是百度了很多结果,很多友友都说没解决问题……)
无法登录后台,点击前台链接或者后台登录时出现"404, not found"
这是nginx的设置时没有注意支持pathinfo导致的,具体关于php pathinfo的信息可以在网上搜索到。解决方法
一般的出现这种情况时,nginx.conf里的的location设置都是类似这样location ~ .*\.php$
要支持pathinfo,要改成
location ~ .*\.php(\/.*)*$
然后在location里加上
set $path_info ""; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1; set $path_info $2; } fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info;
评论 (0)