首页 > 系统相关 >Anolis8.6 hexo+nginx 配置https

Anolis8.6 hexo+nginx 配置https

时间:2024-06-24 11:58:39浏览次数:3  
标签:hexo nginx -- xxx openssl Anolis8.6 usr https local

编辑时间 2023/03/01 23:25

环境准备

站点服务器:Anolis8.6
个人PC:Vscode , nodejs , git , xshell远程工具

搭建开始

家里除了点情况,电闸跳了,由于没ups,nas直接异常掉电,好在数据校验发现没问题,但是debian那台虚机出毛病了nas上我开了两台虚机,另一台gitlab服务器重启后一点问题没有,所以我怀疑是不是debian不稳定。一开始vnc发现黑屏,而且无法操作,因为之前装的带g桌面的,感觉是g桌面坏掉了。
用远程工具连接竟然连的上,但是执行命令出奇的慢,硬盘逻辑坏区检查没问题,读写速度也正常,内存也没满,但是就是很卡。百度了一些资料,说debian的gui确实兼容性不是很稳定,建议更换别的桌面软件,懒得去折腾。之前是项目原因需要接触一下debian,现在暂时没这个需求了,直接重装吧,反正博客数据在github,gitee和自建的gitlab都有备份,正好有的项目需要用到信创平台,趁这个机会体验一下国产化系统。

ups买的apc的390W,除了贵,unraid完美兼容,插电+接通信线秒识别。

Anolis8.6安装与环境准备

Anolis OS镜像下载地址:https://openanolis.cn/download,我这次选择正式版本的GA稳定版本,新的23.0公测版好像是面向社区整合版,8.6GA才是正式版本

按照之前的经验,需要安装nginx,nodejs,hexo。考虑到国产化系统一般会安装在非x86常规架构的设备上,加上yum源的包可能不全,模拟一下这种场景下本地编译安装软件包和依赖库。nodejs比较大,我看yum有这个包就直接安装了。
一般情况下龙蜥系统安装后会安装openssl和ssh服务,因为是预装的,版本比较低,建议先rpm -e --nodeps nginx卸载再进行下一步

先下载这几个包的源码压缩包,是source包

nginx需要gzip、SSL、rewrite几个模块
SSL功能需要openssl库:http://www.openssl.org/
gzip模块需要zlib库:http://www.zlib.net/
rewrite模块需要prce库:http://www.pcre.org/
nginx下载地址:http://nginx.org/en/download.html

将这几个包下载到本地

$ cd /tmp
$ wget https://www.openssl.org/source/openssl-3.0.8.tar.gz
$ wget http://www.zlib.net/zlib-1.2.13.tar.xz
$ wget https://github.com/PCRE2Project/pcre2/archive/refs/tags/pcre2-10.42.tar.gz
$ wget http://hg.nginx.org/nginx/rev/6b81c065e2d3

将openssl,zlib,pcre解压,先进行配置

$ tar -zxvf openssl-3.0.8.tar.gz
$ tar -zxvf zlib-1.2.13.tar.xz
$ tar -zxvf pcre2-10.42.tar.gz
$ cd zlib-1.2.13 
$ ./configure --prefix=/usr/local/zlib
$ make && make install

$ cd pcre2-10.42
$ ./configure --prefix=/usr/local/pcre
$ make && make install

执行过程中可能会遇到openssl编译,出现如下报错

$ cd openssl-3.0.8
$ ./config --prefix=/usr/local/openssl
$ make && make install
Can't locate IPC/Cmd.pm in @INC (@INC contains: /root/Downloads/openssl-3.0.1/util/perl /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 . /root/Downloads/openssl-3.0.1/external/perl/Text-Template-1.56/lib) at /root/Downloads/openssl-3.0.1/util/perl/OpenSSL/config.pm line 18.
BEGIN failed--compilation aborted at /root/Downloads/openssl-3.0.1/util/perl/OpenSSL/config.pm line 18.
Compilation failed in require at /root/Downloads/openssl-3.0.1/Configure line 23.
BEGIN failed--compilation aborted at /root/Downloads/openssl-3.0.1/Configure line 2

这个问题一般是因为刚刚yum remove -y openssl使用yum把openssl卸载了,相关依赖包也一同被卸载了。百度一下基本上就是缺少了部分依赖包,直接装回去就行yum install -y perl-CPAN perl-IPC-Cmd

这里注意一下./configure --prefix=/usr/local/xxxx这条命令,一般source包中都会有一个configure配置命令(有部分包是config文件),用于编译前进行参数配置,--prefix参数用于指定编译安装的目录,如果不加该参数,默认安装在/usr/local/目录下。

三个装好以后,开始安装ngnix,注意参数填写

$ cd /tmp
$ tar -zxvf nginx-1.22.1.tar.gz
$ cd nginx-1.22.1 
$ ./configure --prefix=/usr/local/ngnix --with-http_ssl_module --with-pcre=/tmp/pcre2-10.42 --with-zlib=/tmp/zlib-1.2.13 --with-openssl=/tmp/openssl-3.0.8
$ make && make install
#--with-pcre= 后面是pcre source包解压的路径
#--with-zlib= 后面是zlib source包解压的路径
#--with-openssl=  后面是openssl source包解压的路径

提示编译无误后安装,安装速度会快很多,随后进到默认安装目录进行测试

$ cd /usr/local/nginx/sbin
$ ./nginx -v
nginx version: nginx/1.22.1

如果正常返回版本信息,说明安装没有问题,设置开机自启,新增如下内容,并新增权限

$ vi /etc/rc.local
#...
/usr/local/nginx/sbin
#...
$ chmod 755 /etc/rc.local

一般情况下,设置了ngnix自启已经足够了。为了后面配置核查看ngnix信息方便,可以创建ngnix链接。因为后面要用到openssl,所以也把软连接做一下,并确认命令是否正常

$ ln -s /usr/local/nginx/sbin/ngnix /usr/sbin/ngnix
$ ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
$ ln -s /usr/local/openssl/lib64/libssl.so.3 /usr/lib64/libssl.so.3
$ ln -s /usr/local/openssl/lib64/libcrypto.so.3 /usr/lib64/libcrypto.so.3
$ openssl version
OpenSSL 3.0.8 7 Feb 2023 (Library: OpenSSL 3.0.8 7 Feb 2023)
$ ngnix -v
nginx version: nginx/1.22.1

编辑ngnix配置文件,将http转成https

$ vi /usr/local/nginx/nginx.conf
#...
# http 80端口可以直接注释掉,本项目暂时用不到
# 注意缩进格式
    # HTTPS server
    #
    server {
        listen       443 ssl;
        # 可填写域名或者ip地址
        server_name  xxx.xxx.xxx.xxx;

        # ssl文件目录,直接丢到刚刚ngnix的安装目录里/usr/local/nginx/conf
        ssl_certificate      /usr/local/nginx/conf/server.crt;
        ssl_certificate_key  /usr/local/nginx/conf/server.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        # 这里为站点的资源目录,hexo静态文件存放在hexo项目根目录xxx/public中
        root /xxx/xxx/public;
        # 这里填写根目录,如果hexo上没有设置子目录就按默认填写/即可,如果有设置就填写/子目录名/,proxy_pass位置同理
        location / {
             index index.html index.htm;
             proxy_pass http://xxx.xxx.xxx.xxx:4000/;
        }
    }
#...

创建ssl证书

#创建私有密钥
$ openssl genrsa -out "/usr/local/nginx/conf/server.key" 2048

#创建私有证书,
$ openssl req -new -key "/usr/local/nginx/conf/server.key" -out "/usr/local/nginx/conf/server.csr"
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN          CN  #国家
State or Province Name (full name) []:SX      SX   #省份
Locality Name (eg, city) [Default City]:XA    XA   #城市  
Organization Name (eg, company) [Default Company Ltd]:    #空格
Organizational Unit Name (eg, section) []:                #空格
Common Name (eg, your name or your server's hostname) []:hexo.example.com    
Email Address []:[email protected]                 #邮箱地址
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:123456                # 密码
An optional company name []:                  #空格

#ssl密钥和证书都创建好以后,利用两者创建crt签署证书
$ openssl x509 -req -days 365 -in "/usr/local/nginx/conf/server.csr" -signkey "/usr/local/nginx/conf/server.key" -out "/usr/local/nginx/conf/server.crt"
Signature ok
subject=/C=CN/ST=SX/L=XA/O=Default Company Ltd/CN=hexo.example.com/[email protected]
Getting Private key

#利用openssl签署pem证书
$ openssl dhparam -out /usr/local/nginx/conf/dhparams.pem  2048
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
..............................+..............................................................................................................................................................................................................................+.+..........................................................+...........................................................................................................................................+...........................................................................................................................................................................................................................................................+.....................................................................................+.........................................

ssl证书创建好以后,重启nginx服务,访问hexo站点的https地址即可。

$ nginx -s reload

openEuler22.4安装与环境准备(待更新,2023/3/1)

尝试重起hexo服务

将hexo项目文件从git上pull下来,将node_moudles目录删除直接npm install重新下载依赖库,启动hexo服务发现报错

$ npx hexo server
#...
TypeError: Object.fromEntries is not a function... 
#...

百度搜集资料发现是nodejs版本过低,需要进行升级到14版本以上。因为之前是龙蜥yum源下载的nodejs,看了一下node版本才10版本,yum里面也只有10版本的nodejs

$ yum list nodejs
Repository BaseOS is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
上次元数据过期检查:0:05:37 前,执行于 2023年03月01日 星期三 15时53分18秒。
可安装的软件包
nodejs.x86_64                1:10.24.0-1.0.1.module+an8.7.0+10853+971f45d5                 AppStream

没办法只能自己安装,顺带就试试nodejs的本地编译安装

$ cd /tmp
$ wget https://nodejs.org/dist/v18.14.2/node-v18.14.2.tar.gz
$ tar -zxvf node-v18.14.2.tar.gz
$ cd node-v18.14.2
$ ./configure --prefix=/usr/local/node
$ make && make install

nodejs的编译时间比较长,需要等待比较长的时间,当时电脑就开了2C2G,跑了大概2个多小时,辛亏中途没有报错,不然真的自闭。安装完成以后,可以查看进到安装目录确认是否安装成功,如果出现如下cli交互界面说明顺利安装。

$ cd /usr/local/node/bin
$ ./node
Welcome to Node.js v18.14.2.
Type ".help" for more information.
> .exit

然后创建软连接,测试命令执行正常。

$ ln -s /usr/local/node/bin/node /usr/bin/node
$ ln -s /usr/local/node/bin/npm /usr/bin/npm
$ ln -s /usr/local/node/bin/npx /usr/bin/npx
$ node
Welcome to Node.js v18.14.2.
Type ".help" for more information.
> .exit

重新回到hexo项目目录,再次将node_moudles目录删除npm install重新下载依赖库,防止之前低版本node下载不完全,node启动hexo项目,博客站点恢复完成。

$ cd <hexo项目根目录>
$ rm -rf node_moudles
$ npm install
$ npx hexo server
INFO  Validating config
INFO  Start processing
INFO  Hexo is running at http://localhost:4000/ . Press Ctrl+C to stop.
INFO  
===================================================================
      ______ __  __  ______  __    __  ______                       
     /\__  _/\ \_\ \/\  ___\/\ "-./  \/\  ___\                      
     \/_/\ \\ \  __ \ \  __\\ \ \-./\ \ \  __\                      
        \ \_\\ \_\ \_\ \_____\ \_\ \ \_\ \_____\                    
         \/_/ \/_/\/_/\/_____/\/_/  \/_/\/_____/                    
                                                               
 ______  ______  _____   ______  ______ __  __   __  ______    
/\  == \/\  ___\/\  __-./\  ___\/\  ___/\ \/\ "-.\ \/\  ___\   
\ \  __<\ \  __\\ \ \/\ \ \  __\\ \  __\ \ \ \ \-.  \ \  __\   
 \ \_\ \_\ \_____\ \____-\ \_____\ \_\  \ \_\ \_\\"\_\ \_____\ 
  \/_/ /_/\/_____/\/____/ \/_____/\/_/   \/_/\/_/ \/_/\/_____/
                                                               
  Github: https://github.com/EvanNotFound/hexo-theme-redefine
      current version is v1.1.1,latest version is v1.1.5
===================================================================
Redefine v1.1.1 is outdated, please update to v1.1.5!

为保证远程端口关闭,该服务还在运行(因为正常情况下,窗口关闭行为,尽管设置了后台运行,该远程窗口中所有执行过的语句都会收到中断信号,导致进程被杀掉),可用如下方式执行,关闭远程窗口,hexo服务依旧正常运行

$ vi startserver
#!/bin/bash
cd <hexo项目根目录>
hexo server &
$ chmod +x startserver
$ nohup ./startserver &

备份

得益于NAS,可以直接创建nfs空间进行虚机数据的备份,由于hexo仅仅是框架,只能依靠系统根目录打包进行备份,结合cronb服务完成定时备份计划。
和之前一样,创建备份目录,检测远程nfs服务器挂载目录,并将该目录挂载到本地。查看本地目录有远程nfs挂载说明已经挂载到指定目录了。

$ mkdir -p /backup
$ showmount -e xxx.xxx.xxx.xxx
Export list for xxx.xxx.xxx.xxx:
/mnt/user/system-backup *
$ mount xxx.xxx.xxx.xxx:/mnt/user/system-backup /backup
$ df -h
文件系统                                 容量  已用  可用 已用% 挂载点
devtmpfs                                 888M     0  888M    0% /dev
tmpfs                                    907M     0  907M    0% /dev/shm
tmpfs                                    907M  8.6M  898M    1% /run
tmpfs                                    907M     0  907M    0% /sys/fs/cgroup
/dev/mapper/xxxx                           30G  3.9G   27G   13% /
/dev/mapper/xxxx                           50G  2.2G   48G    5% /data
/dev/mapper/xxxx                          15G  140M   15G    1% /home
/dev/sda1                               1014M  283M  732M   28% /boot
tmpfs                                     79M     0   79M    0% /run/user/0
xxx.xxx.xxx.xxx:/mnt/user/system-backup  8.7T  349G  8.3T    4% /backup

编写备份脚本,参考网上帖子,有些目录和当前系统使用的io设备,硬件配置,挂载设备相关,不需要进行备份,因此编写如下备份脚本

$ vi backup.sh

#!/bin/bash
tar cvzf /backup/backup_"`date +%Y%m%d`".tar.gz --exclude=/proc --exclude=/lost+found --exclude=/backup.tar.gz --exclude=/mnt --exclude=/dev --exclude=/etc --exclude=/fstab --exclude=/boot --exclude=/sys --exclude=/media /

该脚本会将/proc/lost+found/mnt/sys/media除外,其余目录均进行打包备份,并且存放在挂载的NFS/backup目录下,生成文件名包含以YYmmdd为格式的当前日期的tar.gz打包文件。

脚本编写好以后进行保存,然后编辑定时执行脚本

$ crontab -e

0 0 */3 * * /root/backup.sh

该脚本表示,每隔三天执行一次该脚本,即三天进行一次备份。保存以后需要重启cron服务,以生效该配置。

$ systemctl restart crond.service

假如需要进行数据恢复的话,直接将文件拷到进行移植恢复的设备上解压(确保系统版本和内核版本一致),重启系统,该设备就恢复到创建备份时的状态了。

$ tar xvpfz backup.tar.gz -C /

References:

  1. 基础包安装
    Anolis 龙蜥 内网安装nginx、redis、jdk、tomcat 等(make 、gcc命令问题):https://blog.csdn.net/qq_40780434/article/details/127546137
    ubuntu安装openssl出现openssl: error while loading shared libraries: libssl.so.3: cannot open shared obje...:https://blog.csdn.net/weixin_42283887/article/details/122766998
    ./configure --prefix 命令:https://blog.csdn.net/LeslieTsai2019/article/details/119153221

  2. hexo重建问题
    Hexo生成博客遇到的坑:https://blog.csdn.net/zhongyuemengxiang/article/details/122510536
    Linux系统在SSH客户端关闭后继续运行程序:https://blog.51cto.com/u_12956289/2917058

  3. linux备份
    linux 系统 备份与恢复:https://www.cnblogs.com/chenjiye/p/11332387.html
    Linux crontab 命令:https://www.runoob.com/linux/linux-comm-crontab.html
    linux 定时任务crontab用法详解:https://blog.csdn.net/axq19910228/article/details/127725373

标签:hexo,nginx,--,xxx,openssl,Anolis8.6,usr,https,local
From: https://www.cnblogs.com/GKJerry/p/18264760

相关文章

  • 安装 Hexo
    序言安装和配置Git安装NVM和Node安装和配置Git安装和配置HexoGit下载链接#安装Gitapt-get-yinstallgit#配置Gitgitconfigglobaluser.name="testname"gitconfigglobaluser.email="[email protected]"安装NVM和Nodenvm文档nvm-windows下载链接#安装Node......
  • ​HTTP与HTTPS:网络通信的安全卫士
    ✨✨谢谢大家捧场,祝屏幕前的小伙伴们每天都有好运相伴左右,一定要天天开心哦!✨✨ ......
  • Hexo 博客搭建并部署到 GitHub Pages(2024最新详细版)
    效果演示我的博客,欢迎添加友链。前置条件本机已安装好Git和Node.js,Node版本一定不要最新的22版本(会出现各种奇怪的问题),建议16和18稳定版本。Git安装Node.js安装1.安装Hexonpminstallhexo-cli-g终端执行hexo-version出现Hexo版本号,说明安装成功2.......
  • 记一次https通讯调试过程
    情况说明:和服务端https交互时,用域名的方式会有正常的应答,用指定IP的方式则提示异常。代码抛出异常如下:javax.net.ssl.SSLHandshakeException:Remotehostclosedconnectionduringhandshakeatcom.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl,java:88......
  • Nginx 反向代理 (泛域名->泛域名,https,静态文件)
    Nginx反向代理配置指南(泛域名->泛域名,HTTPS,静态文件)完整版server{#监听80端口listen80;listen443sslhttp2;; #...... #泛域名server_name*.{fromName}.com;#获取"*"参数set$subdm'';if($host~*"(.*......
  • 应用同时支持HTTP和HTTPS
    生成证书:keytool-genkeypair-keystoretest.jks-aliastest-keyalgRSA-keysize2048-validity3650应用配置:server:port:18081#httpshttp-port:8081#httpssl:key-store:/test.jks#密钥库路径key-store-password:ENC(djVg6Ri/rp7cHwh9ZTmq/Q==)......
  • java httpsession
    bychatgpt=>HttpSessionHttpSession是JavaServletAPI提供的一个接口,用于管理与单个用户相关的会话信息。会话(session)是在服务器端保存的与客户端用户交互的一系列请求和响应之间的状态信息。以下是HttpSession的详细解释:HttpSession的作用HttpSession用于在用户的多......
  • WPF控件库 https://wpfui.lepo.co/
    wpfui:一个开源免费具有现代化设计趋势的WPF控件库 https://wpfui.lepo.co/合集-C#(46) 1.使用C#将几个Excel文件合并去重分类2023-11-152.C#使用SqlSugar操作MySQL数据库实现简单的增删改查2023-11-163.C#中的类和继承2023-11-174.C#中的virtual和override关键字2023-......
  • pip list https://github.com/pypa/pip 源码
    https://github.com/pypa/pip/blob/main/src/pip/_internal/commands/list.py    packages:"_ProcessedDists"=[      cast("_DistWithLatestInfo",d)      fordinget_environment(options.path).iter_installed_distributions(......
  • springboot——https请求异常Invalid character found in method name. HTTP method n
    遇到问题的情况接口没有配置https,请求时用https会此异常。其他情况1、问题现象java.lang.IllegalArgumentException:Invalidcharacterfoundinmethodname.HTTPmethodnamesmustbetokensatorg.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11Inp......