nginx配置报错

nginx: [emerg] BIO_new_file("/usr/local/nginx/conf/cert/catcook.crt") failed (SSL: error:02001002:

 

nginx: [emerg] BIO_new_file("/usr/local/nginx/conf/cert/catcook.crt") failed (SSL: error:02001002:system library:fopen:No such file or directory:fopen('/usr/local/nginx/conf/cert/catcook.crt','r') error:2006D080:BIO routines:BIO_new_file:no such file)

server {
    listen 443;
    server_name o2o.catcook.top;
    root /home/wwwroot/default/ZooLight/public/;
    index index.html index.htm;
    ssl_certificate  cert/catcook.crt;
    ssl_certificate_key cert/catcook.top.key;
    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 / {
        index index.html index.htm;
    }
}

原因

 

 

配置文件写错了

cert目录下的文件名为catcook.top.crt  catcook.top.key

 

修改配置文件 ssl_certificate  cert/catcook.crt;为 ssl_certificate  cert/catcook.top.crt;

再次执行nginx -s reload

即可

 

### Windows Server 上 Nginx 配置反向代理 404 错误解决方案 当在 Windows Server 上配置 Nginx 作为反向代理时,如果出现 404 错误,通常是因为路径映射不正确或者资源无法被找到。以下是可能的原因以及对应的解决方法: #### 1. 路径配置错误 Nginx 的 `location` 块中的路径与实际的后端服务路径不匹配可能导致 404 错误。确保 `proxy_pass` 中指定的目标 URL 是正确的。 ```nginx server { listen 80; server_name localhost; location /api/ { proxy_pass http://backend_server/api/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location / { root D:/test; index index.html index.htm; } } ``` 注意:这里的 `/api/` 和 `http://backend_server/api/` 必须保持一致[^1]。 #### 2. 后端服务不可达 如果后端服务未启动或网络不通也可能导致 404 错误。可以通过以下方式验证后端服务的状态: - 使用浏览器访问后端服务地址。 - 或者通过命令行工具如 `curl` 测试连接。 ```bash curl -X GET http://backend_server/api/test ``` 如果后端服务正常运行,则需要进一步排查 Nginx 配置文件是否有语法错误。 #### 3. 缓存问题 有时由于缓存机制的存在,可能会导致旧版本的页面显示 404 错误。清除浏览器缓存并刷新页面即可解决问题[^1]。 #### 4. 权限问题 确保 Nginx 对应目录具有读取权限。可以在 Windows 文件夹属性中设置相应的用户组拥有足够的权限来访问该目录下的文件[^2]。 #### 5. 日志分析 查看 Nginx 的 error.log 和 access.log 文件可以帮助定位具体原因。日志位置一般位于安装目录下的 logs 子目录中。 ```nginx error_log logs/error.log debug; access_log logs/access.log main; ``` 通过调试模式的日志输出可以更清晰地了解请求是如何被处理的以及在哪一步出现了问题[^3]。 --- ### 示例代码 下面是一个完整的 Nginx 配置示例用于解决跨域和 404 错误的情况: ```nginx http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream backend { server 192.168.1.10:8080; } server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } location /api/ { proxy_pass http://backend/api/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; } } } ``` 此配置实现了对 `/api/` 请求的转发,并支持 WebSocket 协议升级[^1]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

芝麻开门2015

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值