简体   繁体   中英

.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. All other pages work fine and so does the GET request. The app and API have been deployed on a LINUX machine through NGINX reverse proxy server. Both of them work on HTTP protocol. The feature works for localhost, but not for IP dependent 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.

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. All the pages are accessible without any issue. Just the POST part is not working.

Thank you, in advance.

working fine after commenting

try_files $uri $uri/ =404
  1. cd /etc/nginx/sites-available/
  2. sudo nano default << nginx
  3. edit file then CTR+X and 'y' for yes
  4. sudo systemctl restart nginx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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