git上传文件到腾讯云服务器,我的hexo部署到腾讯云服务器
最近发现腾讯云搞活动,然后就心血来潮买了个服务器,感觉是挺便宜的(肯定是腾讯的套路),还续费了2年,希望自己能玩好这台服务器。昨天刚买完之后,一直在想不知道用来干嘛,想到现在还是不清楚要搞些撒东西出来,所以索性就先把博客迁移到这台服务器吧。
服务器配置
安装Git
yum -y update
yum install -y git nginx
安装git是因为hexo部署静态资源的时候需要有个git仓库
安装nginx用来部署hexo静态资源文件
git安装后需要配置公钥,打开以下文件,把需要部署的客户端的公钥复制到这个文件中就行,这个操作在部署hexo的时候可以跳过openssh的密码验证。(可以不操作,操作更好)
在服务器上操作
vim ~/.ssh/authorized_keys
在hexo客户端中操作
打开GIT GUI 找到HELP找到SHOW SSH KEY
1ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyPyy6mKAQrVQXVWCJ/2SeIDxF6a5FA8exlTTBtuAJZawpgRrnTCma+JFIvdViPH0fNIDLU0IwXZMExK5Gw2u90g3z0O2kJqF1pyAduyKUqd2oSK/aBGgcKCMej5OnS6xfDYqZn+zawsfU58ohUJHWNsXvTtK8XMGKi/N7nBsPxBqgwrTBMwHKIzhWjhv6SquQnnGaNXbddaidImixNyIHsbpJiPAQZtT4RH3WfCasBOtYF5Xl1ZMs07MiGEe+grX3MjrenMe1MJyWEziZTKREaV8jOgVbJi0EjpGTYqDb/oC6paqL4MbpQxQiFD70n2gOjSAyyVWEPfIHKaVl4z+cQ== Administrator@LQN-PC
复制key到authorized_keys 保存即可。
PS:如果服务端重装系统了 则需要清除本地公钥缓存 使用以下命令
ssh-keygen -R 111.230.24.31
新建git仓库
cd /usr/local/wwh
mkdir GitLibrary
chmod -R 755 /data/GitLibrary
初始化
git init --bare hexo.git
vim /usr/local/wwh/GitLibrary/hexo.git/hooks/post-receive
添加以下代码
1
2#!/bin/bash
git --work-tree=/usr/local/wwh/hexo --git-dir=/usr/local/wwh/GitLibrary/hexo.git checkout -f
保存并退出
给文件添加可执行权限
chmod +x /usr/local/wwh/GitLibrary/hexo.git/hooks/post-receive
至此 git仓库配置完成。
nginx配置nginx安装目录在/etc/nginx,配置测试性配置来检查是否安装成功了。
在/usr/local/wwh下新建文件夹 mkdir hexo
cd hexo 新建index.html 文件 vim index.html
文件内容如下:
1
2
3
4
5
6
7
8
9
10
Nginx running
3.配置 Nginx 服务器
vim /etc/nginx/nginx.conf 添加以下配置
1
2
3
4
5
6server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost
root /usr/local/wwh/hexo;//地址为刚才新建hexo文件夹
}
4.启动Nginx 测试是否启动成功
输入命令: systemctl start nginx.service
在没有配置系统启动Nginx的时候只能使用这种方式
5.访问IP
在浏览器输入IP地址:http://111.230.24.31/
会显示Nginx running
表明Nginx启动成功。
部署Hexohexo 客户端安装 配置等不说明,在另外一篇文章中已经提及过了
1.修改nginx.conf 配置文件 vim /etc/nginx/nginx.conf
添加以下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /usr/local/wwh/hexo;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(eot|ttf|otf|woff|svg)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
代码中location 可不添加,location的配置主要是用来做页面缓存,提高访问性能,避免页面加载太慢。
重新启动nginx
systemctl restart nginx.service
nginx 配置完成
2.hexo客户端配置
修改hexo中_config.yml
修改deploy 参数,修改为以下代码
1
2
3
4
5
6deploy:
type: git
repo:
github: git@github.com:wenthywang/wenthywang.github.io.git //部署到github
wwh: root@111.230.24.31:/usr/local/wwh/GitLibrary/hexo //部署到腾讯云服务器
branch: master
执行hexo部署命令
hexo clean //清除本地资源
hexo g -d //生成静态文件 并部署到配置文件中git地址
至此,hexo博客部署完毕。
为Nginx添加系统启动配置在/etc/init.d/目录下编写脚本,名为nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
开启nginx服务
chmod 755 /etc/init.d/nginx
chkconfig --add nginx
nginx启动,停止
service nginx start//启动nginx
service nginx stop//停止nginx
service nginx restart//重启nginx
service nginx reload//修改配置后立马生效
通过系统配置后,nginx可以使用service nginx *的方式来启动了。
定时清除nginx日志
1.修改nginx日志地址
vim /etc/nginx/nginx.conf
修改以下内容
error_log /etc/nginx/logs/error.log warn;
access_log /etc/nginx/logs/access.log main;
2.重新启动nginx
因为重新加载配置不生效,需要重新启动nginx。
service nginx restart
3.添加定时任务(5天前的日志删除)
cd /etc/nginx
mkdir sh
cd sh
vim delete_nginx_logs.sh
添加以下代码
#set the path to nginx log files
log_files_path="/etc/nginx/logs/"
save_days=5
#delete ? days ago nginx log files
find $log_files_path -mtime +$save_days -exec rm -rf {} \;
修改定时任务
crontab -e
添加以下代码 保存
00 00 * * * /bin/sh /etc/nginx/sh/delete_nginx_logs.sh
每天0点0分执行脚本
git上传文件到腾讯云服务器,我的hexo部署到腾讯云服务器相关推荐
- Git上传本地文件到服务器,git上传文件到远程服务器
git上传文件到远程服务器 内容精选 换一换 将文件上传至Windows云服务器一般会采用MSTSC远程桌面连接的方式.本节为您介绍本地Windows计算机通过远程桌面连接,上传文件至Windows云 ...
- Git上传文件代码到GitHub
Git上传文件代码到GitHub 1. 新建一个空文件夹,用来上传文件 2. 点进去空文件夹,鼠标右键,使用Git Bash Here 打开 3. 输入 git init ,初始化,在本地创建一个Gi ...
- 解决git上传文件出错[rejected] master -> master (fetch first) error: failed to push some refs to ‘
如何解决git上传文件出错[rejected] master -> master (fetch first) error: failed to push some refs to ' git p ...
- 解决git上传文件出错[rejected] master -> master (fetch first) error: failed to push some refs to
解决git上传文件出错[rejected] master -> master (fetch first) error: failed to push some refs to 出现这个问题是因为 ...
- git上传文件到gitee
第一步:登录注册gitee,有一个gitee仓库 1.git上传思路 2.git第一次上传步骤 第二步:将创建好的仓库,pull(拉取)到本地(不是第一次上传的情况下) 方式 ...
- git上传文件遇到 错误error: failed to push some refs to
问题场景: 提示:这里简述遇到问题的原因: 场景:在码云中上传文件的同时,会出现这样的问题error: failed to push some refs to 问题描述 提示:这里描述项目中遇到的问题 ...
- 如何使用git上传文件到gitee以及大项目文件(超过100MB的文件如传送)remote: error: File: f422c55c723a183a1944cbec840c0171042(超详细)
目录 1.首先我们要先在gitee上创建一个仓库 2.其次要对仓库进行配置 3.仓库创建完成 4.配置git项目 5.提交文件到gitee的gitTeach仓库 超过100MB的大文件传送的方法 1. ...
- 如何解决git上传文件出错[rejected] master -> master (fetch first) error: failed to push some refs to ‘
使用Git上传本地文件到github时,一直报错,这个问题也困扰了我2天,终于被解决. git add . git commit -m"peTzxz" git push origi ...
- git上传文件失败解决方法
分享一下我在准备上传文件的时候,运行git add . 的时候报错提醒如下. 解决方案 1.找到所要上传的文件目录,因为我们从仓库下载到本地的代码文件,系统会自动隐藏的. 1.1 将隐藏文件.git显 ...
最新文章
- mysql从入门到精通之数据库安装图解
- 读书人:人机融合中的深度态势感知
- leetcode 200岛屿的个数
- 手把手教你pyqt中.qrc图片文件的编写和使用
- 面对人性,有的选择向左,有的向右
- 如何检查python的库是否安装成功_如何测试redis是否安装成功
- akka actor java_现代化的Java(三)——从Hello Akka说起
- 北京大学联合复旦大学发布中文空间语义理解评测SpaCE2021
- Mac电脑如何设置触控栏显示APP控制?
- 最新红旗linux系统,国产系统红旗Linux下载
- 采用QT进行OpenGL开发(三)着色器编程
- matlab空间面板门槛,学习笔记——面板门槛模型
- 信息学奥赛一本通 1197 山区建小学(区间DP)
- CryEngine架构概览
- 你们公司有职业通路图吗
- MATLAB中readtimetable函数用法
- TypeScript进阶 之 重难点梳理
- 考(重点理解哪些属于其他货币资金)、其他货币资金的内容、其他货币资金的账务处理(银行汇票存款、银行本票存款、信用卡存款、信用证保证金存款、存出投资款、外埠存款)
- 远大国际期货交易平台
- SQL Server 中日期比较