$ git clone https://github.com/phaibin/NodeMDBlog
$ cd NodeMDBlog
$ pnpm install
$ node app.js (编辑app.js, 可以修改所监听的端口号3000为其他的端口号)
显示:
test
load
Example app listening at http://:::3000
在浏览器里,访问http://127.0.0.1:3000
新建源帖:
cd views/articles/
nano 2024-11-15-pg.md
cat 2024-11-15-pg.md
显示:
---
title: 美丽的草原,我的家
date: '2024-11-15 23:05'
tags:
- music
- life
---
此处写正文或html codes.
$ cd ../..
$ node app.js
显示:
test
load
Example app listening at http://:::3000
然后按此文https://briteming.blogspot.com/2016/08/systemdnodedaemon.html,
创建NodeMDBlog.service文件,内容如下:
[Unit]
Description=NodeMDBlog app
[Service]
ExecStart=/root/.local/state/fnm_multishells/819828_1742707345686/bin/node /root/NodeMDBlog/app.js
Restart=always
Environment=NODE_ENV=production
WorkingDirectory=/root/NodeMDBlog/
[Install]
WantedBy=multi-user.target
然后,
mv NodeMDBlog.service /etc/systemd/system/
systemctl daemon-reload
systemctl start NodeMDBlog
现在,访问vps-public-ip:3000 ,即可看到静态网站的效果。
systemctl restart NodeMDBlog
systemctl enable NodeMDBlog在其中加入一个server段,如下:
listen 80;
server_name nmb.briten.top;
location / {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:3000;
}
}
每次新建了源帖后,运行: lsof -i:3000
root@racknerd-626f077:~/NodeMDBlog# lsof -i:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node\x20/ 3161 root 20u IPv6 48557 0t0 TCP *:3000 (LISTEN)
root@racknerd-626f077:~/NodeMDBlog#
演示网址:http://nmb.briten.top
项目地址:https://github.com/phaibin/NodeMDBlog
(https://github.com/luckypoemster/NodeMDBlog)
这个程序虽然没有生成静态网站的根目录(含index.html文件的目录),但是它没有使用数据库,所以仍然算是静态博客程序。
No comments:
Post a Comment