Can't figure out how to set up Hexo and NGINX Vhosts config.

August 17, 2018 1.2k views
Node.js Nginx Initial Server Setup MEAN Ubuntu 18.04

Hello everyone,
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?

9 comments
  • You will have to fix the paths of css and whatever else you got in order to make it work. If Hexo provides a way to set the paths at install then you should reinstall it otherwise you have to manually change the paths. You could even use something like sed to fix the paths in one go if it's the same line in all files.

  • @X40C No, Hexo only provides the option to set URL of the root folder as I have mentioned. Since, files will be generated dynamically and new files will be put in manually changing the path of these files doesn't seem like a good idea, but I'll try it though.
    I don't know how to use sed in this case. Can you please elaborate?

  • It seems that Hexo allows you to pick the root directory as well as the domain.

    Website in subdirectory
    If your website is in a subdirectory (such as http://example.org/blog) set url to http://example.org/blog and set root to /blog/.
    

    The above is from https://hexo.io/docs/configuration.html

  • @X40C As you can see in my hexo's _config.yml, I have set my domain to blog.mysite.io and the root directory as /blog/public. If I set it as just /blog or just /, the website breaks.

  • Just installed a Hexo blog on a box with nginx as proxy and everything seems to be working as expected. The website is under blog.domain.tld. I`ve used the default nginx.conf and only added poxypass param to it. I did add the servername and root params as well but nothing was different. This is what the config looks like:

    ``` server_name _;

        location /
        {
                proxy_pass http://127.0.0.1:4000;
        }
    
  • Show 4 more comments
1 Answer
Have another answer? Share your knowledge.