Tools to use
Nginx as the webserver entry and forwarding the specified path as a proxy
Github&&git as source code store
Nodejs I also use node as the server backend language, of course you can use PHP completely
To create a step
Build a warehouse in GitHub
There's not much to explain here, like the demo I built.
Installing Git on the service side
Install the GIT client on your server, and generate your Ssh-key, the generated public key configuration to your GitHub account settings, at this time your server has the operation of your warehouse permissions, you build the warehouse clone to your server, the approximate directory structure is this:
./wwwroot///Site root directory
./demo///Cloned warehouse directory
/demo-server///To update the hook, you'll know what you're doing.
Friendly tip: git
Configure Nginx
Nginx main function is to support static resources, for non-static resources forwarding to the backend, I used here is the Nodejs run back-end services, configured as follows:
server {
Listen 80;
server_name github.xuexb.com;
Root "/home/wwwroot/demo";
AutoIndex on;
# If the directory has MD, rewrite to MD
if (-f $request _filename/readme.md) {
Rewrite (. *) $1/readme.md break;
}
# do the github update hooks
Location =/update {
Proxy_pass http://127.0.0.1:81;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
# Agent All MD to Nodejs
Location ~ \.md$ {
Proxy_pass http://127.0.0.1:81;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
}
Nodejs Enable port 81, send the. md file to 81, send the update hook to 81, the site's root directory is demo
Specific external what domain, what port look at you
Configure GitHub Hooks
Open your GitHub warehouse address/settings/hooks, add a webhooks here, address is the path you update, I am here xxoo.com/update, I use the event is push the time update
Configure back-end
In fact, the back end as long as the function is with GitHub hook with updated files, with what language is not limited to see your mood
Put the backend in the Demo-server directory and listen for 81 ports (because the Nginx is forwarded to 81), and then run the CD if you encounter an updated path. /demo && git pull command to update the file, because the GitHub hook with a very full parameter, you can also detect whether the commit message has the relevant word, you can achieve on-demand update
I'm using Nodejs, just dealing with. MD Document, of course you can use nginx+php to build PHP environment
My nodejs update hook file dot here look
Test hooks
Now you are locally also clone a warehouse, and modify the file after push to GitHub, then you browse your site, is not also updated?
Here you are based on the GitHub site to fix
Online Demo Warehouse Address
Note: Because public warehouses you have to be careful of your privacy, of course tyrants you can buy a private warehouse