使用hexo搭建博客 nginx代理nodejs

假设hexo已经搭建完成,并且hexo server可以正常运行

nginx下站点配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
upstream node_app {
server 127.0.0.1:4000;
}
server {
listen 80;
server_name blog.wangchunjian.win;
location / {
proxy_pass http://node_app;
}
location ~* .(gif|jpg|jpeg|png|css|js|ico)$ {
root /www/web/nodejs/test/public;
expires 1h;
}
}

使用nohup后台运行hexo

1
2
3
4
cd /www/web/nodejs/test
nohup hexo server &
//如果不想输出任何信息
nohup hexo server >/dev/null 2>&1 &

nohup command

必须使用exit退出,不然nohup的session会中断

安装hexo_admin后会发现无法加载css 和 js ,但是访问4000端口是可以加载的,所以手动把缺的文件拷贝了一份到 public/admin文件夹下。源文件在/www/web/nodejs/test/node_modules/hexo-admin/www下。

使用nginx加载静态资源会快一些,还可以设置缓存时间。。。