我是基于CHatGPT实现的AI助手,在此网站上负责整理和概括文章
本文介绍了在网站建立过程中可能遇到的问题和解决方法。首先是遇到400 Bad Request错误,显示“The plain HTTP request was sent to HTTPS port”的情况,解决步骤包括检查和修改Nginx配置文件。其次是在执行hexo指令时出现错误,可能是最近没有打开工作区域文件,解决方法是通过运行npm run server指令。
# 遇到的问题:
# The plain HTTP request was sent to HTTPS port
问题解决步骤:
-
问题描述: 发现访问网站时出现 400 Bad Request 错误,显示 “The plain HTTP request was sent to HTTPS port”。
-
检查 Nginx 配置文件: 打开 Nginx 配置文件,发现在 HTTP server 块中存在一个 rewrite 规则和 if 语句,这可能导致了错误。
-
备份配置文件: 在进行任何修改之前,务必备份 Nginx 配置文件,以防意外情况发生。
-
修改 Nginx 配置文件:
-
HTTP server 块中的 if 语句: 原本的 if 语句会将所有 HTTP 请求都重定向到 HTTPS,但是这样会导致直接在 HTTPS 端口上收到 HTTP 请求,从而引发 400 Bad Request 错误。因此,我们需要修改 if 语句,只有当请求的端口是 80(即 HTTP 请求)时才执行重定向到 HTTPS。
if ($server_port = 80) {
return 301 https://$host$request_uri;
}
-
HTTP server 块中的 rewrite 规则: 原本的 rewrite 规则将所有请求都重定向到 HTTPS,但是在解决 400 Bad Request 错误的情况下,我们需要将这个重定向移除。
# 移除原本的 rewrite 规则
# rewrite ^(.*)$ https://$host$1 permanent;
-
-
保存并关闭配置文件: 在完成修改后,保存并关闭 Nginx 配置文件。
-
重启 Nginx 服务: 使用命令行工具,执行以下命令来重启 Nginx 服务:
nginx -s reload |
这将使新的配置文件生效。
- 测试访问: 使用浏览器访问网站,确认 400 Bad Request 错误是否已经解决。
# Usage: hexo <command> Commands: help Get help on a command.
问题解决步骤:
-
问题描述: 运行 hexo 指令出现错误。
$ hexo clean
Usage: hexo
Commands:
help Get help on a command.
init Create a new Hexo folder.
version Display version information.
Global Options:
–config Specify config file instead of using _config.yml
–cwd Specify the CWD
–debug Display all verbose messages in the terminal
–draft Display draft posts
–safe Disable all plugins and scripts
–silent Hide output on console
-
疑似最近没有打开工作区域文件: 运行以下指令可以解决。
npm run server