I setup a .Net Core application on an AWS EC2 instance and can't seem to get my calls to succeed. Specifically, I find that routes that work just fine on my localhost when I run locally do not work on this Linux box. I followed some instructions from Microsoft to setup Kestrel with an nginx reverse proxy.
Relevent details:
I have a working route that functions on my localhost:
[HttpGet("test")]
[AllowAnonymous]
public ActionResult Test()
{
return Ok("WORKED");
}
On my Linux box, I start dotnet (and have verified nginx is running). I do dotnet MyApp.dll and it says it's listening.
I now make a Postman call to http://api.mydomainhere.com
and in my command/terminal where I have dotnet running, I see the request come in:
[ec2-user@xxxxxx MyApp]$ dotnet MyApp.dll
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/home/ec2-user/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Hosting environment: Production
Content root path: /home/ec2-user/MyApp
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
Request starting HTTP/1.1 GET http://api.mydomainhere.com/api/users/Test application/json 119
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
Request finished in 67.8504ms 404
info: Microsoft.AspNetCore.Server.Kestrel[32]
Connection id "0HM0NUJ8Q68OU", Request id "0HM0NUJ8Q68OU:00000001": the application completed without reading the entire request body.
My nginx setup is:
server {
listen 80;
server_name _;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Despite this, when I call /api/users/test, it 404's me, and if I run the same test locally, it works. Is there a misconfiguration in my app settings in .Net or anything like that?
If I try a curl command from the Linux instance I also get a 404, which means I can't even hit the .Net app right?
ec2-user@xxxx ~]$ curl -v -H "Content-Type: application/json" http://localhost:5000/api/users/test
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET /api/users/test HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.61.1
> Accept: */*
> Content-Type: application/json
>
< HTTP/1.1 404 Not Found
< Date: Wed, 24 Jun 2020 04:22:41 GMT
< Server: Kestrel
< Content-Length: 0
<
* Connection #0 to host localhost left intact
Any suggestions or areas to start looking at?
Thank you!