跳到主要内容

部署

2023年02月20日
柏拉文
越努力,越幸运
前言

博客采取docusaurus快速搭建,服务器购买的是腾讯云轻量级应用服务器,为服务器配套了一个bolawen.com的域名,下面跟大家分享下如何将博客部署到腾讯云服务器的。

一、服务器配置


服务器域名备案

根据指示操作即可,不过之前审核挺长时间的

服务器域名解析

这里我解析了两种域名,分别是 www.bolawen.combolawen.com , 配置效果如图所示:

Preview

如上图: www.bolawen.com 主机域名要配置www,bolawen.com 主域名配置@

服务器防火墙管理

服务器上默认开放80443端口,如果后续要配置MySQLRedis以及服务代理,那么就需要开放其他端口。开放的端口如下所示:

Preview

服务器域名协议证书

为域名申请免费的SSL协议证书

二、Nginx 配置


Nginx 的配置要根据第一步服务器以及域名的配置来,Nginx的配置如下:

  • 配置主域名bolawen.com与主机域名www.bolawen.com
  • 域名 ssl 协议证书配置
  • 访问路径、访问内容配置
worker_processes  1;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name bolawen.com www.bolawen.cn;
if ($host = 'bolawen.cn'){
rewrite ^/(.*) https://bolawen.cn/$1 permanent;
}
if ($host = 'www.bolawen.cn'){
rewrite ^/(.*) https://bolawen.cn/$1 permanent;
}
if ($host = 'bolawen.com'){
rewrite ^/(.*) https://bolawen.com/$1 permanent;
}
if ($host = 'www.bolawen.com'){
rewrite ^/(.*) https://bolawen.com/$1 permanent;
}
location / {
alias C:/bolawen/blog-docusaurus-webpack/build/;
index index.html;
}
location /resource{
alias C:/bolawen/resource;
valid_referers bolawen.com localhost;
if ($invalid_referer) {
return 404;
}
}
location /legacy {
alias C:/bolawen/blog-vuepress-webpack/docs/;
index index.html;
}
location /collect {
alias C:/bolawen/collect/build/;
index index.html;
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^/(collect)/(.+)$ /$1/index.html last;
}
location /server {
rewrite ^/server/(.*) /$1 break;
proxy_pass http://localhost:4000;

}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

}
server {
listen 443 ssl;
server_name bolawen.cn;
ssl_certificate cert/1_bolawen.cn_bundle.crt;
ssl_certificate_key cert/2_bolawen.cn.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
alias C:/bolawen/blog-docusaurus-webpack/build/;
index index.html;
}
location /resource{
alias C:/bolawen/resource;
valid_referers bolawen.com localhost;
if ($invalid_referer) {
return 404;
}
}
location /legacy {
alias C:/bolawen/blog-vuepress-webpack/docs/;
index index.html;
}
location /collect {
alias C:/bolawen/collect/build/;
index index.html;
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^/(collect)/(.+)$ /$1/index.html last;
}
location /server {
rewrite ^/server/(.*) /$1 break;
proxy_pass http://localhost:4000;

}
}
server {
listen 443 ssl;
server_name bolawen.com;
ssl_certificate cert/1_bolawen.com_bundle.crt;
ssl_certificate_key cert/2_bolawen.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
alias C:/bolawen/blog-docusaurus-webpack/build/;
index index.html;
}
location /resource{
alias C:/bolawen/resource;
valid_referers bolawen.com localhost;
if ($invalid_referer) {
return 404;
}
}
location /legacy {
alias C:/bolawen/blog-vuepress-webpack/docs/;
index index.html;
}
location /collect {
alias C:/bolawen/collect/build/;
index index.html;
try_files $uri $uri/ @rewrites;
}
location @rewrites {
rewrite ^/(collect)/(.+)$ /$1/index.html last;
}
location /server {
rewrite ^/server/(.*) /$1 break;
proxy_pass http://localhost:4000;

}
}
}

三、Docusaurus 项目打包配置


  1. 根据Nginx访问路径配置baseUrl

    如果访问路径为 bolawen.com 根路径
    baseUrl : "/"
    如果访问路径为 bolawen.com/xxx
    baseUrl : "/xxx/"