首页 > 系统相关 >debian11 hexo+nginx 配置https

debian11 hexo+nginx 配置https

时间:2024-06-24 11:58:55浏览次数:3  
标签:http hexo -- module nginx https var debian11

环境准备

站点服务器:Debian 11
个人PC:Vscode , nodejs , git , xshell远程工具

这里的站点服务器可以是云服务器,也可以实体机子,我这里使用家里的NAS-unraid开了一台Debian11虚拟机,虚拟机用任意linux发行最新版本均可。

因为某些原因需要去熟悉Debian,发现在Debian系统上编辑文档有点困难 Debian系统vi把我方向键吃了q.q,还是习惯redhat,nas虽然能vnc但是总是不稳定,所以unraid设置虚拟机网络桥接后,直接用远程工具+本地文档编写+git版本管理同步进行搭建。

搭建开始

初步想法就是,基于hexo用静态页面做个人博客站点,hexo有些主题挺贴我的喜好。

快速搭建hexo站点

远程到Debian后,安装git,nodejs,然后使用npm安装hexo,这里选择全局安装,方便调试

$ npm install -g hexo-cli

创建一个站点目录,进行初始化

$ mkdir -p /home/hexo
$ hexo init /home/hexo/demo
$ cd /home/hexo/demo
$ npm install

在站点的根目录下配置站点的基本信息,一般只要去编辑# Site# URL两个部分,其他部分保持默认即可

$ vi /home/hexo/demo/_config.yml

配置好_config.yml文件后,直接启动hexo服务把站点启动,记得目录保持在hexo初始化的根目录。

$ hexo server 
#INFO  Validating config
#INFO  Start processing
#INFO  Hexo is running at http://localhost:4000/ . Press Ctrl+C to stop.

当无ERROR日志则说明顺利启动,并且默认监听在4000端口上,直接访问该页面,站点将按官方默认主题启动,不过讲真默认主题已经蛮好看的了

Ngnix配置HTTPS

不难发现,虽然站点起来了,但是发现只能用http访问,使用https却访问不了。

经过一段时间的百度,考虑采用ngnix做代理转发,将http转成https。首先需要先安装ngnix,apt安装理论上是可行的,因为本地编译安装没尝试过,找了个帖子跟着做试试。

先下载ngnix最新源文件包,apt安装必要的编译工具。

$ apt install -y build-essential libpcre3 libpcre3-dev openssl zlib1g-dev libssl-dev
# 下载源码
$ wget http://nginx.org/download/nginx-1.20.2.tar.gz

# 解压并准备编译
$ tar -xf nginx-1.20.2.tar.gz
$ cd nginx-1.20.2

# 参考帖子的编译参数脚本,其中:
#--prefix:Nginx主要安装路径,后续Nginx子目录依照这个变量展开
#--user:设置Nginx进程启动时,所属的用户
#--group:设置Nginx进程启动时,所属的用户组
$ ./configure \
  --prefix=/usr/local/nginx \
  --user=www \
  --group=www \
  --sbin-path=/usr/local/nginx/sbin/nginx \
  --conf-path=/usr/local/nginx/nginx.conf \
  --error-log-path=/var/log/nginx/error.log \
  --http-log-path=/var/log/nginx/access.log \
  --pid-path=/var/run/nginx.pid \
  --lock-path=/var/run/nginx.lock \
  --http-client-body-temp-path=/var/cache/nginx/client_temp \
  --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
  --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
  --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
  --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
  --with-file-aio \
  --with-threads \
  --with-http_addition_module \
  --with-http_auth_request_module \
  --with-http_dav_module \
  --with-http_flv_module \
  --with-http_gunzip_module \
  --with-http_gzip_static_module \
  --with-http_mp4_module \
  --with-http_random_index_module \
  --with-http_realip_module \
  --with-http_secure_link_module \
  --with-http_slice_module \
  --with-http_ssl_module \
  --with-http_stub_status_module \
  --with-http_sub_module \
  --with-http_v2_module \
  --with-mail \
  --with-mail_ssl_module \
  --with-stream \
  --with-stream_realip_module \
  --with-stream_ssl_module \
  --with-stream_ssl_preread_module

输入配置命令后,如果按如下提示说明无误,可以进行编译

Configuration summary
  + using threads
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx"
  nginx configuration file: "/usr/local/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/cache/nginx/client_temp"
  nginx http proxy temporary files: "/var/cache/nginx/proxy_temp"
  nginx http fastcgi temporary files: "/var/cache/nginx/fastcgi_temp"
  nginx http uwsgi temporary files: "/var/cache/nginx/uwsgi_temp"
  nginx http scgi temporary files: "/var/cache/nginx/scgi_temp"

$ make

编译顺利直接安装,然后创建systemctl守护服务

$ make install

$ vi /usr/lib/systemd/system/nginx.service

按如下内容填写

    [Unit]
    Description=nginx
    After=network.target
      
    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s quit
    PrivateTmp=true
      
    [Install]
    WantedBy=multi-user.target

这样一来,那么ngnix服务就已经安装好了,需要注意如下信息

/usr/local/nginx:为Nginx编译安装的地址。
/usr/local/nginx/nginx.conf:Nginx默认配置文件。
使用systemctl对Nginx进行管理:
启动Nginx服务:systemctl start nginx
重载Nginx配置:systemctl reload nginx
停止Nginx服务:systemctl stop nginx
与systemctl相关的拓展可参考这篇教程:《Linux系统服务神器:systemctl的配置与使用》

接着开始编写配置文件vi /usr/local/nginx/nginx.conf,前面部分内容不需要修改,主要将配置文件最后关于https的部分取消注释并按如下内容填写

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

        # ssl文件目录,图方便直接丢/etc/nginx目录
        ssl_certificate      /etc/nginx/server.crt;
        ssl_certificate_key  /etc/nginx/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文件,直接重载nginx配置会直接报错,我们需要先准备ssl文件并放到配置的目录中。
正常站点是需要进行站点备案、申请域名,然后再填写信息去申请ssl证书。
考虑到目前搭建的只是局域网内使用的,不对外开放,也没有申请域名,直接使用自签SSL证书

ps:虽然对外访问的站点也可以使用自签证书,但因为自签证书安全性不高不推荐使用,仅限调试测试使用。

生成rsa私钥,使用des3算法,2048位,私钥文件保存为server.key

$ openssl genrsa -des3 -out server.key 2048

接下来生成CSR(证书签名请求),执行该语句后会要求依次输入国家,地区,城市,组织,组织单位,Common Name和Email等信息反正是假的,无脑回车按默认值就行

$ openssl req -new -key server.key -out server.csr

最后生成自签名证书,输出自签证书server.crt

$ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

将两个文件放到配置文件填写的目录,重载ngnix配置文件

$ systemctl reload ngnix

然后直接访问https://站点/,除了浏览器会提示告警外,已经可以使用https进行访问了。

References:

  1. ngnix安装
    Debian上编译安装Nginx:https://www.gxlsystem.com/yunwei-33237.html
    debian11编译安装nginx最新稳定版1.22.1https://www.rezhuji.com/os/debian11/build/how_to_make_install_nginx_on_debian11.html
    Debian apt安装nginx并配置反向代理:https://pangruitao.com/post/2106
  2. 反向代理与延伸
    Nginx通过location反向代理网站找不到CSS,JS及图片问题解决方案:https://blog.csdn.net/chengliang666/article/details/126230750
    nginx 配置多个server与多个location:https://blog.csdn.net/GDKbb/article/details/124398453
    Nginx常见场景代理转发配置:https://blog.csdn.net/faye0412/article/details/75200607/
  3. hexo站点搭建
    Hexo官方文档:https://hexo.io/zh-cn/docs/
    Hexo-Redefine主题文档:https://redefine-docs.ohevan.com/docs/intro
    Hexo添加分类及标签:https://juejin.cn/post/6844903830216261645
    Redefine作者站点搭建分享:https://ohevan.com/vercel-hexo-configuration.html

标签:http,hexo,--,module,nginx,https,var,debian11
From: https://www.cnblogs.com/GKJerry/p/18264757

相关文章

  • Anolis8.6 hexo+nginx 配置https
    编辑时间2023/03/0123:25环境准备站点服务器:Anolis8.6个人PC:Vscode,nodejs,git,xshell远程工具搭建开始家里除了点情况,电闸跳了,由于没ups,nas直接异常掉电,好在数据校验发现没问题,但是debian那台虚机出毛病了nas上我开了两台虚机,另一台gitlab服务器重启后一点问题......
  • 安装 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(......