因为微信小程序支持https协议进行网络通信,而不支持http协议,而大模型微调所在的服务器是内网服务器,且没有SSL证书,所以需要申请SSL证书,以及配置Nginx反向代理,才可以访问外网映射过的内网服务器。流程如下图:
一、SSL证书申请
1.申请域名并进行DNS域名解析
为服务器申请域名,将ip地址转为申请的域名,并进行域名解析。
2.申请SSL证书
使用腾讯云平台为域名www.aiguider666.asia申请SSL证书,实现绑定域名,效果如下:
3.SSL证书部署
待SSL证书已签发后,点击下载。由于笔者使用的是Nginx部署,所以下载的是相应的证书。而具体部署可以查看帮助文档。
二、SSL证书部署与Nginx反向代理
在外网服务器上部署SSL证书。首先需要下载Nginx,下载完后,修改…/conf/nginx.config 配置,然后保存。
1、手动下载
将下载的文件 nginx-1.25.1.tar.gz 通过Xftp工具或者通过其他工具上传至Linux 服务器。
2、安装openssl工具并检查配置、指定安装参数
# 安装工具
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
# 重新检查
./configure --prefix=/root/HYJ/nginx-1.27.0/nginx --with-openssl=/root/HYJ/nginx/sbin/openssl-3.0.0 --with-pcre --with-http_ssl_module
注意要添加--with-http_ssl_module,使其能够安装ssl工具,prefix路径为nginx的安装目录不是解压缩的目录。
3、编译和安装
编译和安装命令:make && make install
安装完成后,会在安装目录下生成一个 nginx 的目录,这是我们指定的位置。安装后生成的 nginx 里面有四个目录 (conf html logs sbin),配置文件在 conf/nginx.conf, 启动文件在 sbin/nginx。
接下来使用objs文件夹中的nginx文件替换原来的nginx,成功之后,进入到nginx安装目录下,使用nginx -V 查看ssl是否成功.可以看到这里出现了configure arguments: --with-http_ssl_module 证明已经安装成功.
4.Nginx配置https与反向代理
将证书下载后传到服务器的nginx/conf/cert/下,进入nginx安装目录下的conf文件夹,在文件夹下面会有一个nginx.conf配置文件,进入修改nginx.conf文件。
server {
listen 443 ssl;//端口
server_name www.aiguider666.asia;//申请的域名
ssl_certificate /root/HYJ/VisualGLM-6B-main/nginx-1.27.0/nginx/conf/cert/aiguider666.asia_bundle.pem;//证书位置
ssl_certificate_key /root/HYJ/VisualGLM-6B-main/nginx-1.27.0/nginx/conf/cert/aiguider666.asia.key;
ssl_session_cache shared:SSL:1m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_timeout 5m;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://127.0.0.1:11937;//路由转发到内网服务器通过外网映射暴露的外网ip
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
#root html;
#index index.html index.htm;
}
}
}
为了让SSL生效,需要重启Nginx.。其中nginx -t 是检查配置是否有错。 nginx -s reload 即重新启动Nginx。
(GLM) root@00d919f90700:~/HYJ/VisualGLM-6B-main/nginx-1.27.0/nginx/sbin# ./nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
(GLM) root@00d919f90700:~/HYJ/VisualGLM-6B-main/nginx-1.27.0/nginx/sbin# ./nginx -s reload
这样可以在浏览器输入https://域名来访问服务器。如果访问前端直接https://域名就可以,如果访问后端就https://你的域名/端口号就会访问后端项目。