【问题标题】:.Net core POST API in NGINX reverse proxy throws error 404NGINX 反向代理中的 .Net 核心 POST API 引发错误 404
【发布时间】:2021-06-15 17:46:10
【问题描述】:

这是我第一次发布问题。如果我遗漏了需要分享的内容,请告诉我。

我正在尝试通过我的 C# APP 和 API(单独构建)将一些数据发布到数据库中,但它仅针对 POST API 引发错误 404。所有其他页面都可以正常工作,GET 请求也是如此。该应用程序和 API 已通过 NGINX 反向代理服务器部署在 LINUX 机器上。它们都适用于 HTTP 协议。该功能适用​​于 localhost,但不适用于依赖 IP 的 URL。

这是应用程序服务文件的内容,我不知道其中缺少什么。请注意“/”以及任何需要的地方。在执行 RnD 时,我发现 NGINX 中的 POST 请求被重定向到 GET ,我不知道这是否有帮助,但我想分享一下。

server {
listen      myIP:6002;
server_name attendancepp;
root        /home/user/net-core/Publish/AttendanceModule/AttendanceApp;
location /AttendanceApp/{
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass      http://myIP:6002/;
            proxy_set_header Accept-Encoding "";
            proxy_cache_bypass      $http_upgrade;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_redirect off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

该应用在 URL http://myIP:6002/attendance/allPages 上运行。所有页面都可以毫无问题地访问。只是 POST 部分不起作用。

提前谢谢你。

【问题讨论】:

  • 你在c#中使用的是什么请求方法?您可能需要设置代理属性。
  • 这很简单 [HttpPost("PostEmployees")]。是的,有一个代理属性需要设置,它应该是重定向的,设置为关闭。但即便如此也无济于事。 @jdweng​​span>
  • 尝试将代理设置为空。如果需要代理,代理的超时时间为 30 秒。因此,请检查获得异常需要多长时间。还要从 cmd.exe >IPConfig/all 检查命名空间。您可能需要包含代理的命名空间。

标签: asp.net-mvc asp.net-core asp.net-web-api http-status-code-404 nginx-reverse-proxy


【解决方案1】:

评论后工作正常

try_files $uri $uri/ =404
  1. cd /etc/nginx/sites-available/
  2. sudo nano 默认
  3. 编辑文件,然后 CTR+X 和 'y' 表示是
  4. sudo systemctl 重启 nginx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 2019-11-09
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    相关资源
    最近更新 更多