![1d03702b88d02a03678b708a83bcd66d.png](https://i-blog.csdnimg.cn/blog_migrate/f75ff55e10157afd0663571b29f0df1e.jpeg)
摘要:搭建这个博客可真是一波三折,在博客的起始阶段是部署在Github上,随着越来越多的应用程序转移到了云上,Github已经成为了管理软件开发以及发现已有代码的首选方法。但是毕竟是国外的网站,所以在国内访问速度变的非常慢,于是我又把博客部署到了Coding,他相当于国内版的Github,访问速度非常快,但对移动用户非常不友好,好像移动把Coding给屏蔽了,移动用户访问不了搭建的静态博客,所以这才又把博客部署到了阿里云服务器上,访问速度这才变得快点。
1.准备工作
首先你需要在阿里云上购买一台云服务器,然后在准备一个连接云服务器的软件,这里推荐的是secureCRT,不会的话你可以点这里进行学习
2.安装nginx
2.1安装gcc gcc-c++
yum install -y gcc gcc-c++
2.2安装PCRE库
cd /usr/local/
wget http://downloads.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
tar -xvf pcre-8.37.tar.gz
cd pcre-8.37
./configure
make && make install
pcre-config --version
2.3安装 openssl 、zlib 、 gcc 依赖
cd ..
wget http://nginx.org/download/nginx-1.17.9.tar.gz
tar -xvf nginx-1.17.9.tar.gz
cd nginx-1.17.9
./configure
make && make install
修改配置文件root /home/www/website;
3.安装Git以及Node.js
3.1安装Node.js
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum install -y nodejs
查看是否成功
node -v
npm -v
3.2安装Git及配置仓库
安装git新建git用户
yum install git
adduser git
chmod 740 /etc/sudoers
vi /etc/sudoers
添加 git ALL=(ALL) ALL
chmod 400 /etc/sudoers
sudo passwd git
切换git用户
su git
cd ~
mkdir .ssh
cd .ssh
ssh-keygen
vi authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
创建git仓库
cd ~
git init --bare blog.git
vi ~/blog.git/hooks/post-receive
输入
git --work-tree=/home/www/website --git-dir=/home/git/blog.git checkout -f
保存退出
chmod +x ~/blog.git/hooks/post-receive
新建/home/www/website文件
su root
输入密码
cd /home
mkdir www
cd www
mkdir website
修改文件夹权限
chmod 777 /home/www/website
chmod 777 /home/www
在本地电脑cmd窗口输入
ssh -v git@服务器的公网ip
3.3写入启动脚本
在/etc/init.d/路径下添加脚本文件,名称为nginx,内容如下
#!/bin/bash
#Startup script for the nginx Web Server
#chkconfig: 2345 85 15
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done."
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done."
;;
test)
$nginx -t -c $conf
echo "Success."
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done."
;;
restart)
$nginx -s reload
echo "reload done."
;;
*)
echo "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac
然后执行
chmod +x nginx
控制指令
启动service nginx start
停止service nginx stop
重启service nginx reload
你可以在浏览器输入你的公网ip进入你的博客,如果觉得输ip地址不方便的话也可以买个域名,然后把域名解析到自己的公网ip之后就可以输入个人域名访问了。我的域名正在备案,所以现在只能输入公网ip进行访问。
最后来一个部署到阿里云服务器之后的网站测速图
![cbb8bd58c4f2df7f25213aa307951630.png](https://i-blog.csdnimg.cn/blog_migrate/dae90347af8e8b07918e883f2418ffe1.jpeg)
点击进入nowfitness-个人技术博客