Search code examples
node.jsnginxdeploymentnginx-reverse-proxyhexo

Need help setting up Hexo Blog with NGINX


I need help setting up a blog on my droplet. I have successfully deployed the blog using Hexo at blog.mysite.io but the problem is that the hexo blog redirects it to blog.mysite.io/blog/public. Now, I know why it's happening, its because of the blog config that I set up as:

_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/

My blog is in /www/data/blog. The reason why I set up the root directory as /blog/public is, the css and everything else break if I don't. The blog runs fine but only the HTML part.

Here's the nginx vhosts.conf configuration:

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

}

Anything other than the setting above results in either breaking the site altogether or mismatched paths. So, how can I serve my website directly at blog.mysite.io?


Solution

  • Need to replace root: /blog/public with root: / in Hexo config.

    Nginx can locate full path to your site's directory with root /www/data/blog/public; directive.

    You can also add this settings at the end of Nginx configuration:

    location / {
        # for static content
        root /www/data/blog/public;
        index index.html;
    
        # custom 403/404 redirect
        error_page 403 404 =404 /404/;
    }