使用 gitblog 搭建静态网站

使用 gitblog 搭建静态网站

VPS系统 Ubuntu 18.04,PHP 版本 7.2

安装 nginx php-fpm mbstring 扩展库

apt-get update

apt-get install nginx php-fpm php7.2-mbstring -y

配置 nginx.conf

server {
        listen       80;
        server_name  jockchou.gitblog.cn;
        root         /var/www/;
        index        index.html index.htm index.php;

        location ~ \.(jpg|png|gif|js|css|swf|flv|ico)$ {
                 expires 12h;
        }

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

        location ~* ^/(doc|logs|app|sys)/ {
                return 403;
        }

        location ~ .*\.(php|php5)?$
        {
                fastcgi_connect_timeout 300;
                fastcgi_send_timeout 300;
                fastcgi_read_timeout 300;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include        fastcgi_params;
        }
}

将以上配置中的server_nameroot改成你自己的,fastcgi_pass配成你的CGI进程端口

配置 php-fpm vim /etc/php/7.2/fpm/pool.d/www.conf

默认设置

# Stuff omitted
listen = /var/run/php5-fpm.sock

也就是说 php-fpm 运行时使用的是 Unix Sockets 套接字,需要改成 TCP Sockets 才能让nginx接收到

www.conf相关地方改为以下内容

# Listen on localhost port 9000
listen = 127.0.0.1:9000

/etc/php/7.2/fpm/php.ini文件中开启短标签支持 short_open_tag = On

重启 nginx php-fpm 服务

/etc/init.d/nginx restart

service php7.2-fpm restart

在网站根目录下写一个index.php文件

<?
echo("hello world");
?>

在浏览器中访问域名正常显示 hello world 表示安装环境成功了

安装gitblog

这里下载最新的GitBlog源码包,下传到你的服务器,解压复制包中的所有文件到网站根目录,再访问域名,就能看到GitBlog的默认页面了


本文大致参考gitblog文档编写,加入了安装gitblog之前的细节工作,仅供参考

参考资料:

gitblog文档

Failed to restart php-fpm.service: Unit php-fpm.service not found

PHP-FPM: Configuration the Listen Directive