linux中安装typecho的pathinfo配置

最近,我安装typecho,安装完之后发现,只有首页能够访问,其他的页面报404错误

后来发现时nginx默认情况下不支持pathinfo模式,于是我查找一下资料。终于得到解决。

我的nginx.conf配置如下:

server
{
 listen       80;
 server_name  47.93.101.33;
 server_name  www.xialan.tech;
 index  index.php index.html;
 root  /var/www/html/typecho/build;

 location ~ .*.php(/.*)*$
 {
  #fastcgi_pass  unix:/tmp/php-cgi.sock;
  fastcgi_pass  127.0.0.1:9000;
  fastcgi_index index.php;
  #  limit_conn one 20;
 #设置PATH_INFO,注意fastcgi_split_path_info已经自动改写了fastcgi_script_name变量,
 #后面不需要再改写SCRIPT_FILENAME,SCRIPT_NAME环境变量,所以必须在加载fastcgi.conf之前设置
 # fastcgi_split_path_info  ^(.+.php)(/.*)$;
 # fastcgi_param  PATH_INFO $fastcgi_path_info;
 # fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
 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;

# include fastcgi_params;
     include fastcgi.conf;
 }

 location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
 {
 expires     3d;
 }

 location ~ .*.(js|css)?$
 {
 expires     1h;
 }

}

参考:http://docs.typecho.org/servers

原文地址:https://www.cnblogs.com/wuheng1991/p/8315691.html