Typecho博客搭建

Unix
2021-04-14 / 1 评论 / 297 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2021年06月24日,已超过159天没有更新,若内容或图片失效,请留言反馈。

准备工作,首先装好mysql、php、nginx;

创建typecho博客数据库

create database typecho;

创建站点目录

mkdir -p /var/www/yanxizhu.com

下载并解压Typecho

cd /var/www/yanxizhu.com
yum install wget
wget http://typecho.org/downloads/1.1-17.10.30-release.tar.gz
tar -xzvf 1.1-17.10.30-release.tar.gz

将解压出的文件移动至站点根目录

mv /var/www/yanxizhu.com/build/* /var/www/yanxizhu.com

删除多余文件

rmdir build && rm 1.1-17.10.30-release.tar.gz

配置Nginx和PHP

cd /etc/nginx/conf.d
vim yanxizhu.com.conf

ngxin配置:

80端口

server { 
    listen       80; 
    server_name  yanxizhu.com www.yanxizhu.com;  

    location / { 
        root   /var/www/yanxizhu.com; 
        index  index.html index.htm 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; 
         } 
    } 
    #error_page  404              /404.html; 

    # redirect server error pages to the static page /50x.html 
    # 
    error_page   500 502 503 504  /50x.html; 
    location = /50x.html { 
    root   /usr/share/nginx/html; 
    } 

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80 
    # 
    #location ~ \.php$ { 
    #    proxy_pass   http://127.0.0.1; 
    #} 

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 
    # 
    location ~ \.php$ { 
    root           html; 
    fastcgi_pass   127.0.0.1:9000; 
    fastcgi_index  index.php; 
    fastcgi_param  SCRIPT_FILENAME  /var/www/yanxizhu.com$fastcgi_script_name; 
    include        fastcgi_params; 
    } 

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

SSL 443端口配置

server {
    listen       80;
    server_name  yanxizhu.com  www.yanxizhu.com;
    rewrite ^(.*) https://www.yanxizhu.com$1 permanent;
}

server {
    listen       443 ssl http2 reuseport;
    server_name  yanxizhu.com  www.yanxizhu.com;

    ssl on;
    ssl_certificate /etc/nginx/1_www.yanxizhu.com_bundle.crt;
    ssl_certificate_key /etc/nginx/2_www.yanxizhu.com.key;
    ssl_session_cache shared:SSL:1m;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
        root /var/www/yanxizhu.com;
        index index.html index.htm 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;
        }
    }

    location ~ \.php(\/.*)*$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   /var/www/yanxizhu.com$fastcgi_script_name;
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        include        fastcgi_params;
    }


    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

打开防火墙端口

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent

最后打开域名或ip,按照提示输入数据库密码,在/var/www/yanxizhu.com目录下创建配置文件config.inc.php,内容为页面提示内容。

6

评论 (1)

取消
  1. 头像
    想你的夜
    Windows 10 · Google Chrome

    一次性安装成功,谢谢。表情

    回复