登录后台

页面导航

本文编写于 1750 天前,最后修改于 1747 天前,其中某些信息可能已经过时。

轻量化博客Debin stretch+Typecho+Sqlite

安装nginx

apt-get install aptitude #没有aptitude的话先安装该命令
aptitude install nginx

配置nginx,修改/etc/nginx/sites-available下的default文件,修改后的文件内容如下:

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    server_name _;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
    }

    # pass PHP scripts to FastCGI server
    #
    # location ~ \.php$ {
    location ~ .*\.php(\/.*)*$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;
            include fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
            deny all;
    }
}

安装php-fpm

aptitude install php7.0-fpm php7.0-cli php7.0-curl php7.0-sqlite3 php7.0-gd php7.0-xml php7.0-mcrypt php7.0-mbstring php7.0-iconv 

在/var/www目录下新建info.php文件,访问地址 http://server_domain_or_IP/info.php 测试php是否安装成功。info.php文件内容如下。

<?php
   phpinfo();
?>

安装sqlite

aptitude install sqlite3 php-sqlite3
sqlite3 typecho.db

安装typecho,下载typecho最新版本,将解压后文件移动到/var/www目录下。将/var/www目录权限设置为777.

cd /var/www
sudo wget -c http://typecho.org/downloads/1.1-17.10.30-release.tar.gz
sudo tar xvzf 1.1-17.10.30-release.tar.gz
sudo mv build/* .
chmod -R 777 /var/www

访问地址 http://server_domain_or_IP/install.php 安装并配置typecho。如果php-fpm版本小于5.3.9,需要将/etc/php5/fpm/php.ini中的cgi.fix_pathinfo=0。

修改伪静态

修改/etc/nginx/sites-available/default文件

对应本位置为

server{
    ...
    location / {
        ...
        //这里添加
        ...
        try_files $uri $uri/ =404;
        ...
    }
}

添加如下代码

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;
}

然后重启nginx

在网页管理控制台中点击:设置-永久链接-启用地址重写-自定义文章路径-保存设置