LNMP搭建typecho博客后访问404问题修复

今天闲着无聊看了下其他主流博客,偶然看到了几款很不错的typecho主题,想着就把再撸一个博客系统,由于以前也用过这套博客系统,后来因为功能太少放弃了,现在想想简洁何尝不是另一种美呢?建议新手不要尝试安装这套博客系统,有坑还没填完。

由于环境是LNMP一键的,刚好兼容这套博客系统,于是直接下载用上了,说下遇到的几个问题,刚开始安装阶段很正常,安装完成后主页也能正常访问,正在兴奋之际,偶然发现文章以及后台管理页面全部404,我去,真的见鬼,先说下网上大部分人的解决办法:

  • #### 修改php.ini文件:
cgi.fix_pathinfo=1
  • #### 编辑nginx.conf下的server区域,在location / 下加入如下内容:
        index index.html index.php;

        if (-f $request_filename/index.html){
            rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
            rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
            rewrite (.*) /index.php;
        }
  • #### root 下面插入此行:
include typecho.conf

以上方法对于我无效,你们可以试试,没准行呢,最终正常配置:

server {
    listen 66;
    server_name _;
    index index.php index.html index.htm;
    root /home/wwwroot/typecho;

    #include typecho.conf
    include enable-php-pathinfo.conf;
    #include enable-php.conf;

    location / {
        index index.html index.php;

        if (-f $request_filename/index.html){
            rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
            rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
            rewrite (.*) /index.php;
        }
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;


    location ~ \.php$ {
        try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

经过测试,直接用lnmp命令生成配置即可,生成如下,需要根据实际情况修改:

server
    {
        listen 80;
        #listen [::]:80;
        server_name www.chao.com ;
        index index.html index.htm index.php default.html default.htm default.php;
        root  /home/wwwroot/www.chao.com;

        include rewrite/other.conf;
        #error_page   404   /404.html;

        # Deny access to PHP files in specific directory
        #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; }

        include enable-php-pathinfo.conf;

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

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

        location ~ /.well-known {
            allow all;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /home/wwwlogs/www.chao.com.log;
    }

看到这里,希望你们不要怪我,其实核心代码就一句就搞定:

include enable-php-pathinfo.conf;

你可能感兴趣的:(Linux)