前言 最近正式的服务器要到期了,之前里面部署的长期维护网站都是使用的宝塔面板。
现在打算把网站迁移到几个月前买的项目部署测试服务器,由于里面部署的都是一些可有可无的项目,并且没有做特别规范的项目管理,现在打算把个人长期维护的网站部署上去,显然需要规范一些部署流程。
维护思路 个人长期维护的网站还是使用使用自己熟悉的 GitHub Actions 来自动化部署,不同的是新服务器就不使用宝塔面板了。
而部分完结的临时演示项目,使用 dokcer 部署即可,这样既可以节省服务器资源,也不会影响到本地中长期维护的网站的正常运行。
Docker 容器部署的优点
通过镜像文件生成的容器镜像,可以快速启动、停止、复制和迁移
容器和宿主机之间互相独立,可解决依赖环境版本、端口冲突等问题
多域名配置 为了方便网站管理,我打算模仿宝塔面板的网站管理思路。
具体管理细节就不说了 😂,不过项目部署细节可以阅读我的“项目部署 ”合集
其中域名管理也一样,使用 nginx 的 include 功能来实现多域名访问。
/usr/local/ngnix/conf/nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 http { #... server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } } # spread server include /data/app/vhost/nginx/*.conf; }
/data/app/vhost/nginx/demo.cn.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 server { listen 80; listen 443 ssl; server_name demo.cn; index index.php index.html index.htm default.php default.htm default.html; root /data/app/wwwroot/demo.cn; #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则 #error_page 404/404.html; #HTTP_TO_HTTPS_START #if ($server_port !~ 443){ # rewrite ^(/.*)$ https://$host$1 permanent; #} #HTTP_TO_HTTPS_END ssl_certificate /data/app/vhost/cert/demo.cn/demo.cn.pem; ssl_certificate_key /data/app/vhost/cert/demo.cn/demo.cn.key; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; add_header Strict-Transport-Security "max-age=31536000"; error_page 497 https://$host$request_uri; #SSL-END # handle Vue Router's History Mode location / { try_files $uri $uri/ /index.html; } #ERROR-PAGE-START 错误页配置,可以注释、删除或修改 #error_page 404 /404.html; #error_page 502 /502.html; #ERROR-PAGE-END #禁止访问的文件或目录 location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) { return 404; } access_log /data/app/wwwlogs/demo.cn.log; error_log /data/app/wwwlogs/demo.cn.error.log; }
常见问题 1、nginx: [emerg] the “ssl” parameter requires ngx_http_ssl_module 报错
1 2 3 4 5 6 7 8 9 10 11 12 13 cd /data/local_service/node-v16.18.0-linux-x64./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module make cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bakpkill -9 nginx cd /data/local_service/node-v16.18.0-linux-x64cp ./objs/nginx /usr/local/nginx/sbin//usr/local/nginx/sbin/nginx -V