【问题标题】:Nginx and Jekyll: serving in a subdomainNginx 和 Jekyll:在子域中服务
【发布时间】:2015-04-08 03:36:30
【问题描述】:

我目前正忙于配置 Jekyll 和 nginx 以在 VPS 上协同工作。 本质上,我设置了从本地机器到 VPS 的所有内容和一个 git 挂钩。

这是我的 nginx 配置文件:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /var/www;
    index index.php index.html index.htm;

    server_name server_ip;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /var/www;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
server {
    listen 80;
    server_name server_ip/blog;

    location / {
    root /var/www/blog;
    index index.html index.htm;
    }
}

理想情况下,我现在希望在blog.domain.exampleblog.server_ip 提供/var/www/blog 中的内容。

但是,当jekyll build 运行时,URL 都是错误的。我可以在server_ip/blog 看到index.html,但是在Jekyll 页面上的链接中没有复制URL 中的/blog/ 位。

例如,帖子应位于server_ip/blog/2015/04/07/title,但我得到的网址是server_ip/2015/04/07/title。 CSS 文件和图像也是如此。

非常感谢您的帮助。

【问题讨论】:

    标签: nginx jekyll


    【解决方案1】:

    你必须设置baseurl: "/blog"

    并链接到这样的帖子<a href="{{site.baseurl}}{{post.url}}>...

    一般使用{{site.baseurl}} 来构建任何网址。

    【讨论】:

    • 非常感谢,这很有帮助。设置{{ site.baseurl }} 和仅将"/blog" 附加到{{ site.url }} 之间有区别吗?
    • site.urlprotocol//domain 并且仅对 feed.xml 有用以组成完整的 url。在其他任何地方,我们只需要相对 url,然后我们只需使用 site.baseurl
    • 这很有意义。我希望不必通过数十篇文章来替换链接(尤其是图像)。 @david-jacquel
    猜你喜欢
    • 2017-11-02
    • 1970-01-01
    • 2015-06-04
    • 2018-01-11
    • 1970-01-01
    • 2020-10-07
    • 2019-09-19
    • 2019-11-04
    • 2016-06-17
    相关资源
    最近更新 更多