第五步 - 为 Ghost 安装和配置 Nginx
默认情况下,ghost 会以独立模式运行,你可以不用 Nginx、apache 或 IIS web 服务器直接运行它。但在这篇指南中我们会安装和配置 nginx 和 ghost 一起使用。
用 pkg 命令从 freebsd 库中安装 nginx:
pkg install nginx
下一步,进入 nginx 配置目录并为 virtualhost 配置创建新的目录。
cd/usr/local/etc/nginx/
mkdir virtualhost/
进入 virtualhost 目录,用 nano 编辑器创建名为 ghost.conf 的新文件:
cd virtualhost/
nano-c ghost.conf
粘贴下面的 virtualhost 配置:
server {
listen 80;
#YourDomain
server_name ghost.me;
location ~* \.(?:ico|css|js|gif|jpe?g|png|ttf|woff)$ {
access_log off;
expires 30d;
add_header Pragmapublic;
add_header Cache-Control"public, mustrevalidate, proxy-revalidate";
proxy_pass http://127.0.0.1:2368;
}
location /{
add_header X-XSS-Protection"1; mode=block";
add_header Cache-Control"public, max-age=0";
add_header Content-Security-Policy"script-src 'self' ; font-src 'self' ; connect-src 'self' ; block-all-mixed-content; reflected-xss block; referrer no-referrer";
add_header X-Content-Type-Options nosniff;
add_header X-Frame-Options DENY;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://127.0.0.1:2368;
}
location =/robots.txt { access_log off; log_not_found off;}
location =/favicon.ico { access_log off; log_not_found off;}
location ~/\.ht {
deny all;
}
}
保存并退出。
要启用 virtualhost 配置,你需要把那个文件添加到 nginx.conf。进入 nginx 配置目录并编辑 nginx.conf 文件:
cd/usr/local/etc/nginx/
nano-c nginx.conf
在最后一行的前面,包含 virtualhost 配置目录:
[......]
include virtualhost/*.conf;
}
保存并退出。
用命令 "nginx -t" 测试 nginx 配置,如果没有错误,用 sysrc 添加 nginx 到开机启动:
sysrc nginx_enable=yes
并启动 nginx:
service nginx start
现在测试所有 nginx 和 virtualhost 配置。请打开你的浏览器并输入: ghost.me
ghost.me 成功运行
Ghost.me 正在成功运行。
如果你想要检查 nginx 服务器,可以使用 "curl" 命令。
测试 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 能快速部署并且易于使用和配置。
via: http://linoxide.com/linux-how-to/install-ghost-nginx-freebsd-10-2/
本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-03/129259.htm