Welcome to Jekyll!...Again!
9 min to read
2022转移到腾讯云轻量服务器后,改用wordpress做个人网站。
老实说,很难用。大部分免费模版都是电商样式,少部分能看的几乎没有暴露可调参数。
所以我又麻溜地滚回jekyll啦!
这次花了小半天拿21年的模板存档直接更新了一下,居然就可以使用了!而且终于打通了腾讯云的轻量服务器和jekyll!
小记一下。
速查
静态网页路径 /usr/share/nginx/html
build网页 bundle exec jekyll serve
脚本
因为经常要编译网站,可以新建bat脚本快速运行编译指令——
本地预览——
start cmd /k "cd /d D:\jekyllPkg\myblog &&bundle exec jekyll serve"
上传版本编译——
start cmd /k "cd /d D:\jekyllPkg\myblog &&bundle exec jekyll build"
服务器环境
腾讯云,购买了轻量服务器。安装Centos系统。
※ 其实腾讯云会提供免费的静态网站托管服务,直接上传文件即可在链接对应路径下看到文件,但是没法通过ftp上传文件,只能用腾讯自己开放的端口更新(不想学),此外也不方便修改首页访问路径。所以还是整个云服务器比较自由,方便管理。
云服务器连接ftp
- 安装vsftpd
yum install -y vsftpd //安装vsftpd
systemctl enable vsftpd //设置vsftpd开机自动开启
systemctl enable vsftpd //启动ftp服务器
systemctl start vsftpd //启动ftp服务器
netstat -antup | grep ftp //确认服务是否启动
- 添加ftp用户,这个用户名和密码将用于登录ftp
useradd alfxian //添加用户,这个用户名可自定义,这里用户名是alfxian
passwd alfxian //对添加的用户alfxian设置密码
- 修改配置文件
vim /etc/vsftpd/vsftpd.conf
vsftpd.conf内容如下
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
# When SELinux is enforcing check for SE bool ftp_home_dir
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/xferlog
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode. The vsftpd.conf(5) man page explains
# the behaviour when these options are disabled.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
local_root=/var/ftp/test
allow_writeable_chroot=YES
pasv_enable=YES #pasv_enable=YES 被动模式,pasv_enable=NO 主动模式
pasv_address=xxx.xx.xxx.xx #请修改为您的 Linux 云服务器公网 IP
pasv_min_port=40000
pasv_max_port=45000
- 编辑用户名权限
vim /etc/vsftpd/chroot_list //在文件中添加之前创建的用户名,一个一行
systemctl restart vsftpd //重启FTP服务
-
开放安全组 。确保存在一个全部开放的安全组规则即可。
-
这里使用FileZilla传输文件。输入刚才创建的ftp账户和密码即可。
之后就可以通过ftp上传下载文件啦!速度还是很快的。
Jekyll安装
- 依次安装ruby, rubygem…centos系统用yum install, ubuntu用apt-get
sudo yum install ... //centos系统安装
- 安装jekyll
gem install jekyll bundler //安装jekyll
jekyll new myblog //创建新博客,创建前记得选定博客所在的路径
cd myblog
bundle exec jekyll serve //实时编译,关闭后本地网页路径的模板文件不生效
操作完上述指令,进入http://localhost:4000即可看见当前默认jekykll网站。
nginx同步网页到云服务器
安装完上述步骤后,会迷惑应该把编译完的静态网页_site文件夹传到哪里生效。
这里可以用nginx进行ip地址读取的静态网页路径设定。
yum install nginx -y //安装
nginx //启动
修改/etc/nginx
路径下的nginx.conf
。
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 4096;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
listen [::]:80;
server_name 42.194.190.201; # ip地址
root /usr/share/nginx/html; # 静态网页文件所在路径
# 例如我把_site里的文件全传到这个文件夹,这样ip地址显示的就是静态网页的主页
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
error_page 404 /404.html;
location = /404.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
# Settings for a TLS enabled server.
#
# server {
# listen 443 ssl http2;
# listen [::]:443 ssl http2;
# server_name _;
# root /usr/share/nginx/html;
#
# ssl_certificate "/etc/pki/nginx/server.crt";
# ssl_certificate_key "/etc/pki/nginx/private/server.key";
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 10m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
#
# # Load configuration files for the default server block.
# include /etc/nginx/default.d/*.conf;
#
# error_page 404 /404.html;
# location = /40x.html {
# }
#
# error_page 500 502 503 504 /50x.html;
# location = /50x.html {
# }
# }
}
主要就是修改这两行
server_name 42.194.190.201; # ip地址
root /usr/share/nginx/html; # 静态网页文件所在路径
# 例如我把_site里的文件全传到这个文件夹,这样ip地址显示的就是静态网页的主页
修改后重启nginx
nginx -s reload
到此就可以成功通过云服务器的ip地址访问静态网页了。