Question
Can't figure out how to set up Hexo and NGINX Vhosts config.
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?
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×
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.
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 _;
@X40C Thanks for the follow up. I am having two Vhosts.conf. I am hosting my main site under mysite.tld and another server block for the subomain.mysite.tld. What is the location of the root that you set?
@X40C I just set my root in the vhosts.conf from
/www/data/blog/public/
to/www/data/blog
and it didn’t have any effect whatsoever on the site.My Hexo install was under /root/blog.
@X40C, I just copied all the css files a directory back and it worked. Thanks for the help!