标签 Nginx 下的文章

 以下是portsnap的几种简单用法:

 
    * 第一次使用可以:portsnap fetch extract
    * 以后使用只要:portsnap fetch update 
    * 放在cron里运行:portsnap cron
另外:
更新ports后,如果运行make search name=xxx不成功,请在/usr/ports下运行make fetchindex。
 
 
 
'
 
 

Node.js 是用于开发服务器端应用程序的开源的运行时环境。Node.js 应用使用 JavaScript 编写,能在任何有 Node.js 运行时的服务器上运行。它跨平台支持 Linux、Windows、OSX、IBM AIX,也包括 FreeBSD。Node.js 是 Ryan Dahl 以及在 Joyent 工作的其他开发者于 2009 年创建的。它的设计目标就是构建可扩展的网络应用程序。

Ghost 是使用 Node.js 编写的博客平台。它不仅开源,而且有很漂亮的界面设计、对用户友好并且免费。它允许你快速地在网络上发布内容,或者创建你的混合网站。

在这篇指南中我们会在 FreeBSD 上安装使用 Nginx 作为 web 服务器的 Ghost。我们会在 FreeBSD 10.2 上安装 Node.js、Npm、nginx 和 sqlite3。

第一步 - 安装 Node.js npm 和 Sqlite3

如果你想在你的服务器上运行 ghost,你必须安装 node.js。在这一部分,我们会从 freebsd 移植软件库中安装 node.js,请进入库目录 "/usr/ports/www/node" 并通过运行命令 "make" 安装。

  1. cd/usr/ports/www/node
  2. makeinstall clean

如果你已经安装了 node.js,那就进入到 npm 目录并安装它。npm 是用于安装、发布和管理 node 程序的软件包管理器。

  1. cd/usr/ports/www/npm/
  2. makeinstall clean

下一步,安装 sqlite3。默认情况下 ghost 使用 sqlite3 作为数据库系统,但它也支持 mysql/mariadb 和 postgresql。我们会使用 sqlite3 作为默认数据库。

  1. cd/usr/ports/databases/sqlite3/
  2. makeinstall clean

如果安装完了所有软件,还有检查 node.js 和 npm 的版本:

  1. node--version
  2. v0.12.6
  3.  
  4. npm--version
  5. 2.11.3
  6.  
  7. sqlite3--version
  8. 3.8.10.2

node 和 npm 版本

node 和 npm 版本

第二步 - 添加 Ghost 用户

我们会以普通用户 "ghost" 身份安装和运行 ghost。用 "adduser" 命令添加新用户:

  1. adduser ghost
  2. FILLWithYourINFO

添加用户 Ghost

添加用户 Ghost

第三步 - 安装 Ghost

我们会把 ghost 安装到 "/var/www/" 目录,首先新建目录然后进入到安装目录:

  1. mkdir-p/var/www/
  2. cd/var/www/

用 wget 命令下载最新版本的 ghost:

  1. wget--no-check-certificate https://ghost.org/zip/ghost-latest.zip

把它解压到 "ghost" 目录:

  1. unzip-d ghost ghost-latest.zip

下一步,更改属主为 "ghost",我们会以这个用户安装和运行它。

  1. chown-R ghost:ghost ghost/

都做完了的话,通过输入以下命令切换到 "ghost" 用户:

  1. su-ghost

然后进入到安装目录"/var/www/ghost/":

  1. cd/var/www/ghost/

在安装 ghost 之前,我们需要为 node.js 安装 sqlite3 模块,用 npm 命令安装:

  1. setenv CXX c++;npm install sqlite3--sqlite=/usr/local

注意: 以 “ghost” 用户运行,而不是 root 用户。

现在,我们准备好安装 ghost 了,用 npm 命令安装:

  1. npm install--production

下一步,复制配置文件 "config.example.js" 为 "config.js",用 nano 编辑器编辑:

  1. cpconfig.example.js config.js
  2. nano-c config.js

更改 server 模块的第 25 行:

  1. host:'0.0.0.0',

保存并退出。

现在用下面的命令运行 ghost:

  1. npm start--production

通过访问服务器 ip 和 2368 号端口验证一下。

Ghost 安装完成

Ghost 安装完成

以 “ghost” 用户在 "/var/www/ghost" 目录安装了 ghost。

第四步 - 作为 FreeBSD 服务运行 Ghost

要在 freebsd 上以服务形式运行应用,你需要在 rc.d 目录添加脚本。我们会在 "/usr/local/etc/rc.d/" 目录为 ghost 创建新的服务脚本。

在创建服务脚本之前,为了以服务形式运行 ghost,我们需要安装一个 node.js 模块,用 npm 命令以sudo/root 权限安装 forever 模块:

  1. npm install forever-g

现在进入到 rc.d 目录并创建名为 ghost 的新文件:

  1. cd/usr/local/etc/rc.d/
  2. nano-c ghost

粘贴下面的服务脚本:

  1. #!/bin/sh
  2.  
  3. #PROVIDE:ghost
  4. #KEYWORD:shutdown
  5. PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
  6.  
  7. ./etc/rc.subr
  8.  
  9. name="ghost"
  10. rcvar="ghost_enable"
  11. extra_commands="status"
  12.  
  13. load_rc_config ghost
  14. :${ghost_enable:="NO"}
  15.  
  16. status_cmd="ghost_status"
  17. start_cmd="ghost_start"
  18. stop_cmd="ghost_stop"
  19. restart_cmd="ghost_restart"
  20.  
  21. ghost="/var/www/ghost"
  22. log="/var/log/ghost/ghost.log"
  23. ghost_start(){
  24. sudo-u ghost sh-c"cd $ghost && NODE_ENV=production forever start -al $log index.js"
  25. }
  26.  
  27. ghost_stop(){
  28. sudo-u ghost sh-c"cd $ghost && NODE_ENV=production forever stop index.js"
  29. }
  30.  
  31. ghost_status(){
  32. sudo-u ghost sh-c"NODE_ENV=production forever list"
  33. }
  34.  
  35. ghost_restart(){
  36. ghost_stop;
  37. ghost_start;
  38. }
  39.  
  40. run_rc_command"$1"

保存并退出。

下一步,给 ghost 服务脚本添加可执行权限:

  1. chmod+x ghost

为 ghost 日志创建新的目录和文件,并把属主修改为 ghost 用户:

  1. mkdir-p/var/www/ghost/
  2. touch/var/www/ghost/ghost.log
  3. chown-R/var/www/ghost/

最后,如果你想运行 ghost 服务,你需要用 sysrc 命令添加 ghost 服务到开机启动应用程序:

  1. sysrc ghost_enable=yes

用以下命令启动 ghost:

  1. service ghost start

其它命令:

  1. service ghost stop
  2. service ghost status
  3. service ghost restart

Ghost 服务命令

Ghost 服务命令

第五步 - 为 Ghost 安装和配置 Nginx

默认情况下,ghost 会以独立模式运行,你可以不用 Nginx、apache 或 IIS web 服务器直接运行它。但在这篇指南中我们会安装和配置 nginx 和 ghost 一起使用。

用 pkg 命令从 freebsd 库中安装 nginx:

  1. pkg install nginx

下一步,进入 nginx 配置目录并为 virtualhost 配置创建新的目录。

  1. cd/usr/local/etc/nginx/
  2. mkdirvirtualhost/

进入 virtualhost 目录,用 nano 编辑器创建名为 ghost.conf 的新文件:

  1. cdvirtualhost/
  2. nano-c ghost.conf

粘贴下面的 virtualhost 配置:

  1. server{
  2. listen80;
  3.  
  4. #YourDomain
  5. server_name ghost.me;
  6.  
  7. location~*\.(?:ico|css|js|gif|jpe?g|png|ttf|woff)${
  8. access_log off;
  9. expires30d;
  10. add_headerPragmapublic;
  11. add_headerCache-Control"public, mustrevalidate, proxy-revalidate";
  12. proxy_pass http://127.0.0.1:2368;
  13. }
  14.  
  15. location/{
  16. add_header X-XSS-Protection"1; mode=block";
  17. add_headerCache-Control"public, max-age=0";
  18. add_headerContent-Security-Policy"script-src 'self' ; font-src 'self' ; connect-src 'self' ; block-all-mixed-content; reflected-xss block; referrer no-referrer";
  19. add_header X-Content-Type-Optionsnosniff;
  20. add_header X-Frame-OptionsDENY;
  21. proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for;
  22. proxy_set_headerHost$http_host;
  23. proxy_set_header X-Forwarded-Proto$scheme;
  24. proxy_pass http://127.0.0.1:2368;
  25. }
  26.  
  27. location=/robots.txt{access_log off;log_not_found off;}
  28. location=/favicon.ico{access_log off;log_not_found off;}
  29.  
  30. location~/\.ht{
  31. deny all;
  32. }
  33.  
  34. }

保存并退出。

要启用 virtualhost 配置,你需要把那个文件添加到 nginx.conf。进入 nginx 配置目录并编辑 nginx.conf 文件:

  1. cd/usr/local/etc/nginx/
  2. nano-c nginx.conf

在最后一行的前面,包含 virtualhost 配置目录:

  1. [......]
  2.  
  3. includevirtualhost/*.conf;
  4.  
  5. }

保存并退出。

用命令 "nginx -t" 测试 nginx 配置,如果没有错误,用 sysrc 添加 nginx 到开机启动:

  1. sysrc nginx_enable=yes

并启动 nginx:

  1. service nginx start

现在测试所有 nginx 和 virtualhost 配置。请打开你的浏览器并输入: ghost.me

ghost.me 成功运行

ghost.me 成功运行

Ghost.me 正在成功运行。

如果你想要检查 nginx 服务器,可以使用 "curl" 命令。

测试 ghost 和 nginx

测试 ghost 和 nginx

Ghost 正在 nginx 上运行。

总结

Node.js 是 Ryan Dahl 为创建和开发可扩展服务器端应用程序创建的运行时环境。Ghost 是使用 node.js 编写的开源博客平台,它有漂亮的外观设计并且易于使用。默认情况下,ghost 是可以单独运行的 web 应用程序,并不需要类似 apache、nginx 或 IIS 之类的 web 服务器,但我们也可以和 web 服务器集成(在这篇指南中使用 Nginx)。Sqlite 是 ghost 默认使用的数据库,它还支持 msql/mariadb 和 postgresql。Ghost 能快速部署并且易于使用和配置。

 以下是portsnap的几种简单用法:

 
    * 第一次使用可以:portsnap fetch extract
    * 以后使用只要:portsnap fetch update 
    * 放在cron里运行:portsnap cron
另外:
更新ports后,如果运行make search name=xxx不成功,请在/usr/ports下运行make fetchindex。
 
 
 
'
 
 

Node.js 是用于开发服务器端应用程序的开源的运行时环境。Node.js 应用使用 JavaScript 编写,能在任何有 Node.js 运行时的服务器上运行。它跨平台支持 Linux、Windows、OSX、IBM AIX,也包括 FreeBSD。Node.js 是 Ryan Dahl 以及在 Joyent 工作的其他开发者于 2009 年创建的。它的设计目标就是构建可扩展的网络应用程序。

Ghost 是使用 Node.js 编写的博客平台。它不仅开源,而且有很漂亮的界面设计、对用户友好并且免费。它允许你快速地在网络上发布内容,或者创建你的混合网站。

在这篇指南中我们会在 FreeBSD 上安装使用 Nginx 作为 web 服务器的 Ghost。我们会在 FreeBSD 10.2 上安装 Node.js、Npm、nginx 和 sqlite3。

第一步 - 安装 Node.js npm 和 Sqlite3

如果你想在你的服务器上运行 ghost,你必须安装 node.js。在这一部分,我们会从 freebsd 移植软件库中安装 node.js,请进入库目录 "/usr/ports/www/node" 并通过运行命令 "make" 安装。

  1. cd/usr/ports/www/node
  2. makeinstall clean

如果你已经安装了 node.js,那就进入到 npm 目录并安装它。npm 是用于安装、发布和管理 node 程序的软件包管理器。

  1. cd/usr/ports/www/npm/
  2. makeinstall clean

下一步,安装 sqlite3。默认情况下 ghost 使用 sqlite3 作为数据库系统,但它也支持 mysql/mariadb 和 postgresql。我们会使用 sqlite3 作为默认数据库。

  1. cd/usr/ports/databases/sqlite3/
  2. makeinstall clean

如果安装完了所有软件,还有检查 node.js 和 npm 的版本:

  1. node--version
  2. v0.12.6
  3.  
  4. npm--version
  5. 2.11.3
  6.  
  7. sqlite3--version
  8. 3.8.10.2

node 和 npm 版本

node 和 npm 版本

第二步 - 添加 Ghost 用户

我们会以普通用户 "ghost" 身份安装和运行 ghost。用 "adduser" 命令添加新用户:

  1. adduser ghost
  2. FILLWithYourINFO

添加用户 Ghost

添加用户 Ghost

第三步 - 安装 Ghost

我们会把 ghost 安装到 "/var/www/" 目录,首先新建目录然后进入到安装目录:

  1. mkdir-p/var/www/
  2. cd/var/www/

用 wget 命令下载最新版本的 ghost:

  1. wget--no-check-certificate https://ghost.org/zip/ghost-latest.zip

把它解压到 "ghost" 目录:

  1. unzip-d ghost ghost-latest.zip

下一步,更改属主为 "ghost",我们会以这个用户安装和运行它。

  1. chown-R ghost:ghost ghost/

都做完了的话,通过输入以下命令切换到 "ghost" 用户:

  1. su-ghost

然后进入到安装目录"/var/www/ghost/":

  1. cd/var/www/ghost/

在安装 ghost 之前,我们需要为 node.js 安装 sqlite3 模块,用 npm 命令安装:

  1. setenv CXX c++;npm install sqlite3--sqlite=/usr/local

注意: 以 “ghost” 用户运行,而不是 root 用户。

现在,我们准备好安装 ghost 了,用 npm 命令安装:

  1. npm install--production

下一步,复制配置文件 "config.example.js" 为 "config.js",用 nano 编辑器编辑:

  1. cpconfig.example.js config.js
  2. nano-c config.js

更改 server 模块的第 25 行:

  1. host:'0.0.0.0',

保存并退出。

现在用下面的命令运行 ghost:

  1. npm start--production

通过访问服务器 ip 和 2368 号端口验证一下。

Ghost 安装完成

Ghost 安装完成

以 “ghost” 用户在 "/var/www/ghost" 目录安装了 ghost。

第四步 - 作为 FreeBSD 服务运行 Ghost

要在 freebsd 上以服务形式运行应用,你需要在 rc.d 目录添加脚本。我们会在 "/usr/local/etc/rc.d/" 目录为 ghost 创建新的服务脚本。

在创建服务脚本之前,为了以服务形式运行 ghost,我们需要安装一个 node.js 模块,用 npm 命令以sudo/root 权限安装 forever 模块:

  1. npm install forever-g

现在进入到 rc.d 目录并创建名为 ghost 的新文件:

  1. cd/usr/local/etc/rc.d/
  2. nano-c ghost

粘贴下面的服务脚本:

  1. #!/bin/sh
  2.  
  3. #PROVIDE:ghost
  4. #KEYWORD:shutdown
  5. PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin"
  6.  
  7. ./etc/rc.subr
  8.  
  9. name="ghost"
  10. rcvar="ghost_enable"
  11. extra_commands="status"
  12.  
  13. load_rc_config ghost
  14. :${ghost_enable:="NO"}
  15.  
  16. status_cmd="ghost_status"
  17. start_cmd="ghost_start"
  18. stop_cmd="ghost_stop"
  19. restart_cmd="ghost_restart"
  20.  
  21. ghost="/var/www/ghost"
  22. log="/var/log/ghost/ghost.log"
  23. ghost_start(){
  24. sudo-u ghost sh-c"cd $ghost && NODE_ENV=production forever start -al $log index.js"
  25. }
  26.  
  27. ghost_stop(){
  28. sudo-u ghost sh-c"cd $ghost && NODE_ENV=production forever stop index.js"
  29. }
  30.  
  31. ghost_status(){
  32. sudo-u ghost sh-c"NODE_ENV=production forever list"
  33. }
  34.  
  35. ghost_restart(){
  36. ghost_stop;
  37. ghost_start;
  38. }
  39.  
  40. run_rc_command"$1"

保存并退出。

下一步,给 ghost 服务脚本添加可执行权限:

  1. chmod+x ghost

为 ghost 日志创建新的目录和文件,并把属主修改为 ghost 用户:

  1. mkdir-p/var/www/ghost/
  2. touch/var/www/ghost/ghost.log
  3. chown-R/var/www/ghost/

最后,如果你想运行 ghost 服务,你需要用 sysrc 命令添加 ghost 服务到开机启动应用程序:

  1. sysrc ghost_enable=yes

用以下命令启动 ghost:

  1. service ghost start

其它命令:

  1. service ghost stop
  2. service ghost status
  3. service ghost restart

Ghost 服务命令

Ghost 服务命令

第五步 - 为 Ghost 安装和配置 Nginx

默认情况下,ghost 会以独立模式运行,你可以不用 Nginx、apache 或 IIS web 服务器直接运行它。但在这篇指南中我们会安装和配置 nginx 和 ghost 一起使用。

用 pkg 命令从 freebsd 库中安装 nginx:

  1. pkg install nginx

下一步,进入 nginx 配置目录并为 virtualhost 配置创建新的目录。

  1. cd/usr/local/etc/nginx/
  2. mkdirvirtualhost/

进入 virtualhost 目录,用 nano 编辑器创建名为 ghost.conf 的新文件:

  1. cdvirtualhost/
  2. nano-c ghost.conf

粘贴下面的 virtualhost 配置:

  1. server{
  2. listen80;
  3.  
  4. #YourDomain
  5. server_name ghost.me;
  6.  
  7. location~*\.(?:ico|css|js|gif|jpe?g|png|ttf|woff)${
  8. access_log off;
  9. expires30d;
  10. add_headerPragmapublic;
  11. add_headerCache-Control"public, mustrevalidate, proxy-revalidate";
  12. proxy_pass http://127.0.0.1:2368;
  13. }
  14.  
  15. location/{
  16. add_header X-XSS-Protection"1; mode=block";
  17. add_headerCache-Control"public, max-age=0";
  18. add_headerContent-Security-Policy"script-src 'self' ; font-src 'self' ; connect-src 'self' ; block-all-mixed-content; reflected-xss block; referrer no-referrer";
  19. add_header X-Content-Type-Optionsnosniff;
  20. add_header X-Frame-OptionsDENY;
  21. proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for;
  22. proxy_set_headerHost$http_host;
  23. proxy_set_header X-Forwarded-Proto$scheme;
  24. proxy_pass http://127.0.0.1:2368;
  25. }
  26.  
  27. location=/robots.txt{access_log off;log_not_found off;}
  28. location=/favicon.ico{access_log off;log_not_found off;}
  29.  
  30. location~/\.ht{
  31. deny all;
  32. }
  33.  
  34. }

保存并退出。

要启用 virtualhost 配置,你需要把那个文件添加到 nginx.conf。进入 nginx 配置目录并编辑 nginx.conf 文件:

  1. cd/usr/local/etc/nginx/
  2. nano-c nginx.conf

在最后一行的前面,包含 virtualhost 配置目录:

  1. [......]
  2.  
  3. includevirtualhost/*.conf;
  4.  
  5. }

保存并退出。

用命令 "nginx -t" 测试 nginx 配置,如果没有错误,用 sysrc 添加 nginx 到开机启动:

  1. sysrc nginx_enable=yes

并启动 nginx:

  1. service nginx start

现在测试所有 nginx 和 virtualhost 配置。请打开你的浏览器并输入: ghost.me

ghost.me 成功运行

ghost.me 成功运行

Ghost.me 正在成功运行。

如果你想要检查 nginx 服务器,可以使用 "curl" 命令。

测试 ghost 和 nginx

测试 ghost 和 nginx

Ghost 正在 nginx 上运行。

总结

Node.js 是 Ryan Dahl 为创建和开发可扩展服务器端应用程序创建的运行时环境。Ghost 是使用 node.js 编写的开源博客平台,它有漂亮的外观设计并且易于使用。默认情况下,ghost 是可以单独运行的 web 应用程序,并不需要类似 apache、nginx 或 IIS 之类的 web 服务器,但我们也可以和 web 服务器集成(在这篇指南中使用 Nginx)。Sqlite 是 ghost 默认使用的数据库,它还支持 msql/mariadb 和 postgresql。Ghost 能快速部署并且易于使用和配置。

Blblog 是一个仅使用 Markdown 文件的极简博客。它受到Telegra.ph、Medium或Hexo
的强烈启发。该项目是为个人使用而创建的,但欢迎您将这个项目做得更好!
首页示例
文章页演示

如何安装?
只需 git clone https://github.com/Donokami/Blblog.md.git .在/var/www/html/(或任何网络服务器根目录)中使用或在此处下载存档并解压缩到您的网络服务器根目录中。

在 Apache2 上
您需要使用sudo a2enmod rewrite. 如果 url 重写不起作用,这可能是由于您的 Apache2 配置;要纠正此问题,请apache2.conf在/etc/apache2(在基于 linux 的发行版上)编辑您的文件并将任何文件替换AllowOverride None为AllowOverride All.

在 Nginx 上
替换/etc/nginx/sites-available/default成这个配置,然后使用重启Nginx

nginx -t
nginx -s reload
配置
你必须./include/Config.php根据你自己的网络服务器和你未来博客的数据来配置文件(阅读评论以获得更多帮助)。另外,用你自己的资产替换./assets/img/static/bg.jpg&./assets/img/meta/cover.jpg

如何写一篇文章?
在文章文件夹中创建一个新文件,如wow.md. .md 非常重要,如果扩展名不在这里,您的文件将不会被读取。现在,在您的文件中,您需要编写一个标题,如下所示:

title: Hey, Read me !
desc: Here is the description of the article, where you can write some informations.
author: Kiyoshi
cover: assets/img/articles/readme_cover.png //(Optional) It can be either a file or an url.

tags: configuration blblog markdown php //(Optional)

Here is the content of _your article

PHP代码目录
只需本地生成.md文件就可以更新BLOG文章
.md Markdown文件里的代码写法

这就是全部!

扩展想法:可以采集文文章,然后批量生成.md文件,上传后批量更新文章。实现某些目地。