Ubuntu 安装Ghost博客

2025-11-23 21:38:52

1、

准备安装环境

使用Ubuntu Linux命令更新 Ubuntu 软件,安装开发工具包、解压缩工具、Vim 和 wget:

sudo apt-get update

sudo apt-get upgrade -y

sudo aptitude install -y build-essential zip vim wget

2、首先我们安装Nginx启动Web服务器,安装成功后输入你的服务器IP(桌面版就直接在浏览器打开 127.0.0.1)就可以看到“Welcome to Nginx!”。

在Linnx命令行下执行如下命令:

sudo apt-get install nginx

 

启动Nginx服务:

sudo service nginx start

 

3、安装Node.js

方法一:下载源代码后执行编译和安装。缺点:编译程序往往要消耗很多时间。

  

从官方仓库获得最新的 Node.js 源代码包:

wget http://nodejs.org/dist/node-latest.tar.gz 

tar -xzf node-latest.tar.gz 

cd node-v* 

 

安装 Node.js

./configure

make

sudo make install

 

方法二:从网络仓库下载已经编译完成的安装包。

首先添加仓库:

add-apt-repository ppa:chris-lea/node.js

更新索引:

apt-get update

直接下载安装 Nodejs:

apt-get install nodejs

完成后我们可以通过 node -v 和 npm -v 命令来检查 Node.js 的版本。两种方法的最终效果都一样的。

4、创建一个文件夹,用来放置网站文件和 Ghost 博客程序。

sudo mkdir /var/www/ 

cd /var/www/

 

从官方网站下载最新版本的 Ghost(ghost-latest.zip):

wget https://ghost.org/zip/ghost-latest.zip

 

解压:

unzip -d ghost ghost-latest.zip

 

进入 Ghost 安装目录:

cd /var/www/ghost

 

执行安装命令,安装 Ghost:

sudo npm install --production

 

安装完成后用 npm start 命令启动开发者模式下的 Ghost,用于检查有没有安装成功。 成功了,Ghost会运行在本地局域网内 127.0.0.1:2368。如果是在电脑上安装的,用浏览器访问此地址即可预览 Ghost。

1、要想让Ghost作为网站登上因特网的台面,我们还不能让其运行在默认的开发模式。需要让其运行在生产模式,且当其运行进程退出时自动重启。因此我们可以使用进程守护程序“PM2”达到此目的。还要配置一下Nginx服务器。

2、

以生产模式运行 Ghost

 

进入到刚才的Ghost安装目录

cd /var/www/ghost

 

执行下面的命令安装PM2:

sudo npm install pm2 -g

我们要设置环境变量为“production”生产模式!“index.js”是程序启动的入口。最后给这个PM2的进程命名为"Ghost" 于是,执行下面的命令:

NODE_ENV=production pm2 start index.js --name "ghost"

让PM2知道在开机后自动运行我们的网站:

pm2 startup Ubuntu

pm2 save

提示1: pm2 kill ghost //关闭所有PM2进程。

提示2: pm2 <start|stop|restart> ghost  //分别是启动|停止|重启 ghost程序 。

提示3: pm2 startup <centos|ubuntu|amazon> //这是让pm2能够能够在这3个系统上自动启动。

(提示:至此,PM2已经可以守护Ghost博客在线运行)

3、配置 Nginx 的反向代理(这是最容易出错的一点)

前面,如果你已经安装好了 Nginx。 新建一个 Nginx 代理配置文件,并将代理指向到本地的Ghost端口:

sudo vim /etc/nginx/sites-available/ghost.conf

注意:如果你读到这里,CentOS与Ubuntu不同。Centos服务器应该是 sudo vim /etc/nginx/conf.d/ghost.conf

先按下 S 键,再将如下内容拷贝到到新文件中。注意将 My-Domain-Name.com 改成你要设置的网址。在编辑完成后,按下 Esc,输入 :wq! 回车退出。

 

server {

    listen 80;

    server_name My-Ghost-Blog.com;

    location / {

        proxy_set_header   X-Real-IP $remote_addr;

        proxy_set_header   Host      $http_host;

        proxy_pass         http://127.0.0.1:2368;

    } 

}

建立配置文件的相互关联:

sudo ln -s /etc/nginx/sites-available/ghost.conf /etc/nginx/sites-     enabled/ghost.conf

重新启动 Nginx 服务器,让设置生效。

sudo service nginx restart

4、工作都已做完了,Ghost博客成功运行!但是别忘了修改服务器时区哦。错误的系统时间会导致博客程序显示错误的文章发布日期。

sudo apt-get install -y ntpdate ntp

sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢