MALOUDA-PSA 2025-02-02 18:58 采纳率: 85.6%
浏览 4

nginx.conf配置的问题

为什么/abnormal 这个访问没有问题 /htmljson访问出了问题,同样是C++后端:
并且https://127.0.0.1:8226/htmljson 可以访问

根据CHATGPT建议移除了后一个rewrite:

    location ^~ /abnormal {
            rewrite ^/abnormal/(.*)$ /$1 break;
            proxy_pass https://127.0.0.1:8226;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;

            access_log C:\\sys\\tools\\nginx24\\logs\\min_access.log;
            error_log C:\\sys\\tools\\nginx24\\logs\\min_error.log debug;

            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
                return 204;
            }
        }
        
    location ^~ /htmljson {
            #rewrite ^/htmljson/(.*)$ /$1 break;
            proxy_pass https://127.0.0.1:8226;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;

            access_log C:\\sys\\tools\\nginx24\\logs\\min_access.log;
            error_log C:\\sys\\tools\\nginx24\\logs\\min_error.log debug;

            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

            if ($request_method = 'OPTIONS') {
                add_header 'Access-Control-Allow-Origin' '*';
                add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
                add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
                return 204;
            }
        }
        


浏览器报错:

     GET https://47.120.18.242/htmljson 404 (Not Found)
loadJson @ index-lTPAd5Xj.js:2
(匿名) @ index-lTPAd5Xj.js:2了解此错误AI
index-lTPAd5Xj.js:2 There was a problem with the fetch operation: HTTP error! status: 404
loadJson @ index-lTPAd5Xj.js:2
await in loadJson
(匿名) @ index-lTPAd5Xj.js:2了解此错误AI
index-lTPAd5Xj.js:2 Full error object: Error: HTTP error! status: 404
    at Proxy.loadJson (index-lTPAd5Xj.js:2:5529)

  • 写回答

2条回答 默认 最新

  • 专家-赤兔[在线] 优质创作者: 编程框架技术领域 2025-02-02 19:12
    关注

    以下回复引自免费微信小程序:皆我百晓生。 如问题解决,还请采纳。如仍有疑问,请回复留言或私信博主,以便获得更精准的帮助。

    在使用NGINX时,如果遇到异常访问(如 /ABNORMAL 或者 /HTMLJSON),可能是因为服务器配置或NGINX自身设置的问题。以下是几个可能导致上述情况的原因及解决方法:

    原因分析

    1. 错误的域名解析:确保您的域名与NGINX的地址空间匹配。

      • 确保URL中的HTTP://HTTPS://是正确的,避免使用WWW.
      • 检查NGINX是否正确地设置了允许外部IP通信的规则。
    2. 网络连接问题:检查网络连通性,并确认NGINX监听的端口和协议已正确设置。

      • 使用命令行工具如NGINX的NSLOOKUP来检查网络连接状态。
      • 确认NGINX是否正确开启了HTTP、HTTPS服务,并且正确配置了相应的端口号。
    3. 防火墙限制:某些防火墙可能会阻止NGINX对外部访问。确保NGINX的安全设置符合当前的安全策略。

      • 查看NGINX的安全配置,特别是关于安全区域和策略的详细说明。
      • 如果需要安全访问,可以尝试修改NGINX的安全级别或者添加适当的ACL。
    4. 配置文件错误:检查NGINX的配置文件,尤其是NGINX.CONFSERVER部分。

      • 阅读相关的配置指南,了解如何在NGINX中进行必要的更改。
      • 尝试使用不同的配置选项或参数,看看是否有改进的地方。
    5. 服务器负载过重:如果NGINX的负载过高,可能会导致性能下降。

      • 减少NGINX的资源消耗,例如关闭不必要的缓存,减少请求次数等。

    解决方案

    • DNS查询错误

      • 确保NGINX正确地解析了域名。
      • 检查DNS记录,确保它们指向正确的主机。
    • 防火墙限制

      • 确保NGINX监听的端口和协议已经正确设置。
      • 检查防火墙设置,确保NGINX的端口没有被禁止。
    • 安全配置

      • 修改NGINX的安全设置,如开启SSL/TLS验证,添加适当的ACL。
      • 关闭不必要的安全功能,如过滤特定类型的数据包。
    • 压力测试

      • 测试NGINX的性能瓶颈,看看是否有潜在的瓶颈影响了访问。
    • 重启NGINX

      • 如果NGINX本身出现问题,可能需要通过控制台重新启动。
    • 升级到最新版本

      • 更新NGINX至最新的稳定版,以修复可能存在的兼容性问题。

    以上步骤可以帮助您确定并解决问题。如果问题仍然存在,可能需要更深入的技术支持或专业的帮助。

    评论

报告相同问题?

问题事件

  • 创建了问题 2月2日