需要帮助以NGINX设置Hexo Blog

时间:2018-08-17 12:02:34

标签: node.js nginx deployment nginx-reverse-proxy hexo

我需要在我的Droplet上建立博客的帮助。我已经在 blog.mysite.io 上使用Hexo成功部署了博客,但问题是hexo博客将其重定向到 blog.mysite.io/blog/public 。现在,我知道它为什么会发生,这是因为我将博客配置设置为:

_config.yml

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://blog.mysite.io/
root: /blog/public
permalink: :year/:month/:day/:title/

我的博客位于 / www / data / blog 中。我将根目录设置为 / blog / public 的原因是,如果没有,css和其他所有内容都会中断。该博客运行正常,但只有HTML部分。

以下是nginx vhosts.conf 配置:

server {
    server_name blog.mysite.io;

    root /www/data/blog/public;
    index index.html index.htm;

        location /
        {
                proxy_pass http://127.0.0.1:4000;
        }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/blog.mysite.io/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/blog.mysite.io/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

除上述设置外,任何其他操作都会导致完全中断站点或路径不匹配。 那么,如何直接在 blog.mysite.io 上为我的网站提供服务?

1 个答案:

答案 0 :(得分:0)

需要在Hexo配置中将root: /blog/public替换为root: /

Nginx可以使用root /www/data/blog/public;指令找到您网站目录的完整路径。

您还可以在Nginx配置的末尾添加以下设置:

location / {
    # for static content
    root /www/data/blog/public;
    index index.html;

    # custom 403/404 redirect
    error_page 403 404 =404 /404/;
}