5udou.cn网站重新部署

发表于 2024-05-09
更新于 2024-05-24
分类于 技术专栏
阅读量 162
字数统计 4077

最近把2015年做的结婚纪念网站重新迁移了到新的服务上,把一些技术栈替换了一下,但是在部署的时候出现了一些小问题,这里记录下,方便以后回溯。

1、winston日志

打印到日志文件里面会出现color无法识别,出现类似这样的字符:

2024-05-09 17:14:45.123 ^[[32minfo^[[39m: ,因为不是在shell中,所以对应的颜色转成了乱码,这里我们只需要在winstonformat判断上,对于写入Console的才启用colorize,参考这里的源码:https://github.com/linxiaowu66/doumi-wedding-memory/blob/main/src/main.ts]]

2、nginx部署与SSL证书

之前部署blog.5udou.cn的时候,还是很轻松的,可是这次部署5udou.cn就没那么简单了,在执行certbot --nginx -v的时候一直报错:

1Certbot failed to authenticate some domains (authenticator: nginx). The Certificate Authority reported these problems: 2 Domain: www.5udou.cn 3 Type: dns 4 Detail: During secondary validation: DNS problem: query timed out looking up A for www.5udou.cn; DNS problem: query timed out looking up AAAA for www.5udou.cn 5 6Hint: The Certificate Authority failed to verify the temporary nginx configuration changes made by Certbot. Ensure the listed domains point to this nginx server and that it is accessible from the internet. 7

因为我原本是想访问www.5udou.cn的时候也能够访问的,后来发现是nginxdns上其实没有做对应的一些跳转,因此最后琢磨了一遍,实现的效果是:

  • 访问www.5udou.cn和5udou.cn都会统一跳转到5udou.cn

对应的配置如下: image.png

,之后我们在nginx设置双域名访问:

1# the IP(s) on which your node server is running. I chose port 3000. 2upstream 5uDou { 3 server 127.0.0.1:8080; 4 keepalive 8; 5} 6 7# the nginx server instance 8server { 9 server_name 5udou.cn www.5udou.cn; 10 access_log /var/log/nginx/5uDou.log; 11 12 # pass the request to the node.js server with the correct headers 13 # and much more can be added, see nginx config options 14 location / { 15 proxy_set_header X-Real-IP $remote_addr; 16 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 17 proxy_set_header Host $http_host; 18 proxy_set_header X-NginX-Proxy true; 19 20 proxy_pass http://5uDou/; 21 proxy_redirect off; 22 } 23} 24 25server { 26 # 当访问www的时候,进行跳转到5udou.cn 27 if ($host = www.5udou.cn) { 28 return 301 https://5udou.cn$request_uri; 29 } 30 31 server_name 5udou.cn www.5udou.cn; 32 listen 80; 33}

之后再执行certbot --nginx -v的时候选择的域名,选择5udou.cn即可:

1root@iZf8zgdg257k255er1mlb2Z:/etc/nginx/sites-enabled# certbot --nginx -v 2Saving debug log to /var/log/letsencrypt/letsencrypt.log 3Plugins selected: Authenticator nginx, Installer nginx 4 5Which names would you like to activate HTTPS for? 6We recommend selecting either all domains, or all domains in a VirtualHost/server block. 7- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 81: 5udou.cn 92: blog.5udou.cn 103: www.5udou.cn 11- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 12Select the appropriate numbers separated by commas and/or spaces, or leave input 13blank to select all options shown (Enter 'c' to cancel): 1 14Requesting a certificate for 5udou.cn 15Performing the following challenges: 16http-01 challenge for 5udou.cn 17Waiting for verification... 18Cleaning up challenges 19 20Successfully received certificate. 21Certificate is saved at: /etc/letsencrypt/live/5udou.cn/fullchain.pem 22Key is saved at: /etc/letsencrypt/live/5udou.cn/privkey.pem 23This certificate expires on 2024-08-07. 24These files will be updated when the certificate renews. 25Certbot has set up a scheduled task to automatically renew this certificate in the background. 26 27Deploying certificate 28Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/www.5udou.cn 29Successfully deployed certificate for 5udou.cn to /etc/nginx/sites-enabled/www.5udou.cn 30Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/www.5udou.cn 31Congratulations! You have successfully enabled HTTPS on https://5udou.cn 32 33- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 34If you like Certbot, please consider supporting our work by: 35 * Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate 36 * Donating to EFF: https://eff.org/donate-le 37- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

公众号关注一波~

微信公众号

关于评论和留言

如果对本文 5udou.cn网站重新部署 的内容有疑问,请在下面的评论系统中留言,谢谢。

网站源码:linxiaowu66 · 豆米的博客

Follow:linxiaowu66 · Github