首页 > 解决方案 > .net core mvc API 使用 NGINX 反向代理部署在 UBUNTU 上,POST 请求抛出 404 错误

问题描述

我创建了一个 .net 核心 API,它又在 .net 核心 Web 应用程序中使用。它们使用其 IP 和自定义端口部署在 ubuntu 机器上。API 和 webapp 的服务文件已粘贴在下面。当我尝试通过网络应用程序发布数据时,它会给出错误“404”,指出找不到发布功能。

API 和 webApp 都通过 IP 托管,但是当它们使用 localhost 托管时,POST 请求可以正常工作。这没有帮助,因为这些将通过 IP 本身托管。

在下面发布我的文件,请帮助。

server {
listen      6002;
server_name attendanceapp;
root        /home/arun/net-core/Publish/AttendanceModule/AttendanceAPI;
location /attendancepp/{
             proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass      http://192.168.0.27:6002;
            proxy_redirect off;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Accept-Encoding "";
            proxy_cache_bypass      $http_upgrade;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'Content-Type';
            add_header 'Content-Type' 'application/json';
    }

}

server {
listen      192.168.0.27:6001;
server_name attendancepi;
root        /home/arun/net-core/Publish/AttendanceModule/AttendanceAPI;
location /attendanceapi/ {
            proxy_redirect off;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_set_header Connection $http_connection;
            proxy_cache_bypass $http_upgrade;
    }

}

错误画面

标签: ubuntu.net-corehttp-status-code-404asp.net-core-webapinginx-reverse-proxy

解决方案


推荐阅读