咬人猫 发布的文章

在 conf 文件中增加 rewrite ^(.*)$ https://$host$1 permanent;,示例如下:

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

    root /var/www/html/typecho;

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

    server_name _;

    # http 强制转成 https
    rewrite ^(.*)$ https://$host$1 permanent;

    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(\/.*)*$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
    }

    if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php$1 last;
    }
}

一、环境

Debian 10.2 64bit

二、安装步骤

  1. 下载安装包

    wget https://github.com/typecho/typecho/releases/latest/download/typecho.zip
  2. 解压

    unzip -d /var/www/html/typecho typecho.zip
  3. 安装
    执行 http://网址/install.php

    • 提示 上传目录无法写入,请手动将安装目录下的/usr/uploads目录的权限设置为可写然后继续升级,执行以下语句:

      chmod -R 777 /var/www/html/typecho/
    • 提示 缺少扩展 mbstring、mysqli等错误,执行以下语句:

      apt install php-mbstring
      apt install php-mysql
    • 提示 无法连接数据库,需要提前新建好数据库 typecho

三、使用

  1. 打开除了主页外,其他链接都提示 404,需要修改 /etc/nginx/conf.d/*.conf

    location ~ .*\.php$

    改为

    location ~ .*\.php(\/.*)*$
  2. typecho 的每个地址都包含 index.php

    • 打开 设置/永久链接,把 是否使用地址重写功能 功能启用,并忽略警告保存。
    • 修改 /etc/nginx/conf.d/*.conf,增加如下代码:

      if (!-e $request_filename) {
       rewrite ^(.*)$ /index.php$1 last;
      }

四、参考