先附上白嫖阿里云ESC地址:真香
Answer
[TOC]

1. 使用的工具

WinSCP(可视化界面操作linux系统下的文件夹),Xshell5(远程连接工具)

2. 修改配置规则

点击实例id—本实例安全组—配置规则—添加80端口

3. 安装nginx

安装nginx需要相关的依赖库,我们先进行库的安装。

3.1 安装gcc gcc-c++

1
yum install -y gcc gcc-c++

3.2 安装PCRE库

1
2
3
4
5
6
7
8
9
10
11
12
13
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

3.3 安装 openssl 、zlib 、 gcc 依赖

1
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel

3.4 安装nginx

安装nginx一定要在local文件夹下

1
2
3
4
5
6
7
8
9
10
11
cd /usr/local/

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

3.5 修改配置文件

把/usr/local/nginx/conf/nginx.conf右击使用内部编辑器打开,修改为如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / {
root /home/www/website; #此处要改
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/www/website; #此处要改
}

保存退出

3.6 启动nginx

启动后在浏览器中输入公网IP,即可弹出nginx或centos初始界面(验证nginx是否成功安装)

常用命令:
启动:/usr/local/nginx/sbin/nginx
重启:/usr/local/nginx/sbin/nginx -s reload
检测配置文件是否正常:/usr/local/nginx/sbin/nginx -t

4. 安装Git以及Node.js

4.1 安装Node.js

1
2
3
curl -sL https://rpm.nodesource.com/setup_10.x | bash -

yum install -y nodejs

查看是否成功

1
2
3
node -v

npm -v

可以显示版本号即为成功

4.2 安装Git及配置仓库

1
2
3
4
5
6
7
yum install git

adduser git

chmod 740 /etc/sudoers

vi /etc/sudoers

在如下位置添加
git ALL=(ALL) ALL
vi指令执行之后按i进入输入模式
编辑完成之后按一下esc
然后输入:wq即可退出

4.3 执行以下指令更改文件夹权限

1
2
3
chmod 400 /etc/sudoers

sudo passwd git

4.4 切换git用户并且建立密钥

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
su git

cd ~

mkdir .ssh

cd .ssh

vi authorized_keys

找到C:\Users\用户名\.ssh\id_rsa.pub复制粘贴(以前配置过的把known_hosts删除,不然后面会报错)

chmod 600 ~/.ssh/authorized_keys

chmod 700 ~/.ssh

4.5 创建git仓库

1
2
3
4
5
6
7
8
9
10
11
12
13
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

保存退出(:wq)

chmod +x ~/blog.git/hooks/post-receive

4.6 新建/home/www/website文件夹

在root用户下执行,所限先su root切换为root账户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
su root

输入密码

cd /home

mkdir www

cd www

mkdir website

修改文件夹权限 这步很重要

chmod 777 /home/www/website

chmod 777 /home/www

4.7 测试本地是否能够远程连接服务器

在cmd或git中输入ssh -v git@服务器的公网ip(我的cmd显示的不是内部命令,所以我用了git,可以连上)

4.8 修改本地博客目录中的配置文件_config.yml

1
2
3
4
deploy:
type: git
repo: git@公网IP:/home/git/blog.git
branch: master

这里说一下
url: #域名没备案好就填公网IP
root: / #这里一开始没加东西,就报错,说是找不到网站目录,后来加了个/就好了。

5. 问题总结

线上服务器进行了ip地址的修改,开始出现Host key verification failed的时候,以为删除自己的know_hosts文件即可,但是没有解决本质问题。

解决方法

1
2
3
mknod -m 644 /dev/tty c 5 0

chmod o+rw /dev/tty

公私钥认证
解决了上面的问题,发现之前由于不清楚原因搞乱了.ssh目录的权限,无法公私钥认证登陆,这里记录一下权限设置:
~/.ssh目录的权限必须是0700
~/.ssh/authorized_keys文件权限必须是0600

1
2
3
chmod 600 ~/.ssh/authorized_keys

chmod 700 ~/.ssh

·······························································参考博客(https://lneverl.gitee.io/posts/2092ec56.html)