1

我正在尝试建立一个幽灵博客并想使用 nginx 来处理传入的请求。幽灵博客应该可以通过子 uri 中的 url 访问,例如:http://mydomain.com/blog文章将具有类似http://mydomain.com/blog/article1的 url

到目前为止,我尝试配置这样的设置没有奏效,而且我总是收到 404 错误。这是我的 config.js:

var path = require('path'),
    config;

config = {
    // ### Production
    // When running Ghost in the wild, use the production environment
    // Configure your URL and mail settings here
    production: {
        url: 'http://mydomain.com/blog',
        mail: {},
        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            },
            debug: false
        },
        server: {
            // Host to be passed to node's `net.Server#listen()`
            host: '127.0.0.1',
            // Port to be passed to node's `net.Server#listen()`, for iisnode set this to `process.env.PORT`
            port: '2368'
        }
    }
}
// Export config
module.exports = config;

这是我的 nginx 配置:

server {
    listen 0.0.0.0:80;
    server_name mydomain.com;
    access_log /var/log/nginx/mydomain-com.log;

    location /blog {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header HOST $http_host;
        proxy_set_header X-NginX-Proxy true;

        proxy_pass http://127.0.0.1:2368;
        proxy_redirect off;
    }
}

谁能告诉我我做错了什么?

4

3 回答 3

1

location适用于使用路径访问博客:

location ~^/blog(?<tail>.+$) {
   # more proxy stuff
   proxy_pass http://localhost:2368$tail;
}

它的性能是另一回事。

但正如您可能在 Ghost 中所读到的config.js

提供网站链接时使用的 url,例如 RSS 和电子邮件。主机名后不得包含路径后缀 - (尚)不支持“子目录”!

在我的测试中,博客主页可以正常使用/blog,但它包含指向文章的错误链接,没有前导/blog. 但是,如果您导航到一篇文章,然后在地址栏上编辑它的 URL,插入/blog它也可以。

所以我想你需要在 Ghost 上破解一下或者等待下一个版本。

于 2013-11-20T23:58:09.253 回答
0

也许你可以使用子域来做到这一点。而且您不需要更改任何关于 Ghost 的配置。

upstream frontends {
    ip_hash;
    server 127.0.0.1:2368;
}

server {
    listen       80;
    server_name  blog.mydomain.com;

location / {
    proxy_pass http://frontends;
}

server {
    listen       80;
    server_name  mydomain.com;

    location / {
    root   html;
    index  index.html index.htm;
}
于 2013-11-13T05:41:48.337 回答
0

对子目录的支持仅在 Ghost 0.4 版本中实现,如果您之前尝试使用某个版本,它可能不起作用,至少现在应该容易得多,您可以对 url 进行 1 对 1 代理到您的后端服务器。

于 2014-02-01T19:32:53.177 回答