简体   繁体   English

.Net core POST NGINX 中的 API 反向代理抛出错误 404

[英].Net core POST API in NGINX reverse proxy throws error 404

This is my first time posting a question.这是我第一次发布问题。 Kindly let me know if I am missing something that needs to be shared.如果我遗漏了需要分享的内容,请告诉我。

I am trying to POST some data into database through my C# APP and API (separately build), but it throws error 404 only for the POST API.我正在尝试通过我的 C# APP 和 API(单独构建)将一些数据发布到数据库中,但它仅针对 POST ZDB974238714CA8DE634A7CE1D083A14F 引发错误 404。 All other pages work fine and so does the GET request.所有其他页面都可以正常工作,GET 请求也是如此。 The app and API have been deployed on a LINUX machine through NGINX reverse proxy server.该应用程序和 API 已通过 NGINX 反向代理服务器部署在 LINUX 机器上。 Both of them work on HTTP protocol.它们都适用于 HTTP 协议。 The feature works for localhost, but not for IP dependent URL.该功能适用于 localhost,但不适用于依赖 IP 的 URL。

Here is the content of service file for the app, I do not know what is missing in it.这是应用程序服务文件的内容,我不知道其中缺少什么。 Please take care of the "/" as well where ever it is needed.请注意“/”以及任何需要的地方。 While performing RnD, I found that the POST request in NGINX gets redirected to GET, I don't know if this will be helpful or not, but felt like sharing.在执行 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;
    }

} }

The app works on the URL http://myIP:6002/attendance/allPages.该应用程序适用于 URL http://myIP:6002/attendance/allPages。 All the pages are accessible without any issue.所有页面都可以毫无问题地访问。 Just the POST part is not working.只是 POST 部分不起作用。

Thank you, in advance.先感谢您。

working fine after commenting评论后工作正常

try_files $uri $uri/ =404
  1. cd /etc/nginx/sites-available/ cd /etc/nginx/sites-available/
  2. sudo nano default << nginx须藤纳米默认<< nginx
  3. edit file then CTR+X and 'y' for yes编辑文件然后 CTR+X 和 'y' 是
  4. sudo systemctl restart nginx sudo systemctl 重启 nginx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM