How to Deploy Nginx + Hexo on Ubuntu Server with SSL and auto post
Local PC
Install Node.js
Firstly you should download Node.js installer in https://nodejs.org/en/download/ with msi version. Just go ahead to install it.Now you can type npm -v
in CLI. It’s all right if you see the output is the version of Nodejs.
Install Git
It’s the same as Node.js.Just remember check set environment variables.
Generate RSA cert
ssh-keygen -t rsa
,you will see id_rsa and id_rsa.pub in C:\Users\%USERNAME%\.ssh.They will be used later.
Install Hexo
1 | npm install hexo-cli -g |
Config
_config.yml
must be edited if you want to deploy in a server.
1 | # Deployment |
YSERVERIP and GITPATH should be replaced latter
Server
Install
1 | apt-get update |
please copy id_rsa which in step Generate RSA cert
by into authorized_keys
1 | chmod 600 /home/git/.ssh/authorized_keys |
How to work
If you were correct before then you can now use the command line to connect to ssh
1 | ssh git@ip |
You will be needed a proxy If you connect ssh timeout.Proxifer can’t proxy the cmd.exe(at least for me).But There is a way to handle it.Adding CONFIG C:\Users\%USERNAME%\.ssh
.The content is as follows
1 | ProxyCommand "C:\Program Files\Git\mingw64\bin\connect.exe" -S 127.0.0.1:10808 %h %p |
Set Auto Post
before setting hook it will be needed to create some directories for your blog.
1 | mkdir /home/repo |
Now setting hook
1 | vim /home/repo/hexo.git/hooks/post-receive |
1 |
|
1 | chown -R git:git /home/repo/hexo.git/hooks/post-receive |
/home/repo/hexo.git
it the GITPATH in _config.yml
nginx
Uploading ssl certificate to server if you want to enable SSL. Modify /etc/nginx/sites-available/default
1 | server { |
nginx -s reload