✅ ASP.NET Web API cant be reached: (SOLVED: Setup reverse proxy)
im making a small web api using ASP.NET and im having issues with running my code on a server to test stuff, the app says it runs on port 5000 but upon trying to reach it, curl and other request methods fail
this is what it says in the console:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /home
31 Replies
(I haven't worked with ASP.NET in a good while so im unsure of what to do)
Have you setup a reverse-proxy with your web server (nginx, apache, etc.) and pointed it to your ASP site? Additionally have you linked your site's DNS records to your server's IP?
i mean i have run ASP.NET Blazor apps on it before and using the port i didnt have to add reverse proxy to it to work, it seems that the server is only listening to localhost in this case but i have no idea how to get rid of that
Your site will be run on localhost on your server, and you setup a reverse-proxy to your site's localhost:port, and that's how it's accessed from the web as a standalone website
Alternative way is, you can do https://my.ip.is.cool:port to access it directly w/o a website
yes but how is it that my blazor app can run perfectly fine without that but my asp.net web api cant
it says its not reachable
everything works like this but as soon as i pull it onto a server it becomes unreachable even with correct port and all
is the port used by another app mayhaps?
additionally you can do
x.UseUrls("http://0.0.0.0:your-beloved-port")
in your HostBuilder to reserve a portthe thing is, on my pc it shows me 2 ports, 5035 and 7188, on my server i only have 1 port bound to localhost
ill check
What host is the one that the server says it's listening on?
localhost:5000
Have you tried to run this same command on your server to check if it responds?
for example this one just works
ill check
alright now if you setup a reverse-proxy to go to that port from a website, for an example, then you should be able to access the API that way
ill try to set a reverse proxy
maybe its rly the fix
thats how i host all my ASP mvc sites
if you need, i have the nginx file for reverse-proxy that i can provide
nah i have a reverse proxy ready i did it before with api.mydomain and service.mydomain
but thanks
no problem
actually 5000 is still bound to service ill try to just ping that endpoint
yes
works?
thanks
there ya go
no problem
glad i switched to nginx apache sucks with reverse proxy
nginx W
fr
theres no way im ever gonna use a different webserver again
anyways, thanks a lot, i appreciate it
so others can see too
do
$close
to resolve this$close
Use the
/close
command to mark a forum thread as answered