solo博客使用非docker方式进行https部署
solo博客使用非docker方式进行https部署
服务器上请通过 Docker 部署。但是我服务器资源有限,不想安装docker,直接以编译包的形式运行,节省资源。
如果不会solo源码编译,请查看:solo博客源码使用idea编译运行
数据库配置
Solo 默认使用的是嵌入式数据库 H2。H2 是一个轻量级的 Java SQL 数据库,适合开发和测试环境。
例如使用mysql,手动建库(库名 solo ,字符集使用 utf8mb4 ,排序规则 utf8mb4_general_ci )
create database solo default character set utf8mb4 collate utf8mb4_general_ci;
create user 'root'@'127.0.0.1' identified by '123456';
grant all privileges on *.* to 'root'@'127.0.0.1';
flush privileges;
solo根目录下:local.properties
配置文件修改数据库连接信息,然后重启服务程序即可。
#### MySQL runtime ####
runtimeDatabase=MYSQL
jdbc.username=xd
jdbc.password=Xt_2022
jdbc.driver=com.mysql.cj.jdbc.Driver
jdbc.URL=jdbc:mysql://124.01.1.1:3306/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
启动命令讲解
核心启动参数说明:
--listen_port
:进程监听端口--server_scheme
:最终访问协议,如果反代服务启用了 HTTPS 这里也需要改为https
--server_host
:最终访问域名或公网 IP,不要带端口--server_port
:最终访问端口,使用浏览器默认的 80 或者 443 的话值留空即可
设置自定义访问端口:9168
/home/dtian/project/jdk-17.0.9/bin/java -cp "lib/*:." org.b3log.solo.Server --server_port=9168 --listen_port=9168
服务器设置自定义访问端口,后台启动
nohup /home/dtian/project/jdk-17.0.9/bin/java -cp "lib/*:." org.b3log.solo.Server --server_port=9168 --listen_port=9168 > ../solo-log.txt 2>&1 &
配置https访问
重要! 原有的接口代理可以不用修改,在服务器内部使用 http
nginx.conf
文件配置如下:
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
# nginx 配置hthps代理
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;
upstream backend {
server localhost:9168; # java 应用监听端口
}
server {
listen 80;
listen [::]:80;
server_name 124.71.65.251;
root /usr/share/nginx/html;
# 将所有请求重定向到HTTPS
return 301 https://$server_name$request_uri;
access_log off;
# 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 124.71.65.251;
root /usr/share/nginx/html;
# 证书文件地址
ssl_certificate "/etc/pki/nginx/server.crt";
ssl_certificate_key "/etc/pki/nginx/server.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
proxy_pass http://backend$request_uri;
# 关键这里将端口进行传递
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 10m;
}
# 博客外部图片资源代理
location /images/ {
alias /home/dtian/images/;
autoindex 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 {
}
}
}
# nginx 配置校验
[root@hcss-ecs-cf99 nginx]# nginx -t
# nginx 配置重新加载
[root@hcss-ecs-cf99 nginx]# nginx -s reload
当然了,我们要为自己的博客配置HTTPS,那么上述命令中的--server_scheme
的值必须是 https, 通过HTTPS访问时会产生异常。
https 后台启动命令:
nohup /home/dtian/project/jdk-17.0.9/bin/java -cp "lib/*:." org.b3log.solo.Server --server_port=9168 --listen_port=9168 --server_scheme https > ../solo-log.txt 2>&1 &
部署效果
应为域名需要备案,个人学习使用,使用ip直接部署,效果如下:
原文地址:https://blog.csdn.net/w2462140956/article/details/143588358
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!