✅ 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
Somgör from Human Resources
(I haven't worked with ASP.NET in a good while so im unsure of what to do)
Hackmagician
Hackmagician13mo ago
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?
Somgör from Human Resources
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
Hackmagician
Hackmagician13mo ago
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
Somgör from Human Resources
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
Somgör from Human Resources
everything works like this but as soon as i pull it onto a server it becomes unreachable even with correct port and all
Hackmagician
Hackmagician13mo ago
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 port
Somgör from Human Resources
the thing is, on my pc it shows me 2 ports, 5035 and 7188, on my server i only have 1 port bound to localhost
Somgör from Human Resources
ill check
Hackmagician
Hackmagician13mo ago
What host is the one that the server says it's listening on?
Somgör from Human Resources
localhost:5000
Hackmagician
Hackmagician13mo ago
Have you tried to run this same command on your server to check if it responds?
Somgör from Human Resources
for example this one just works
Somgör from Human Resources
ill check
Hackmagician
Hackmagician13mo ago
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
Somgör from Human Resources
ill try to set a reverse proxy maybe its rly the fix
Hackmagician
Hackmagician13mo ago
thats how i host all my ASP mvc sites if you need, i have the nginx file for reverse-proxy that i can provide
Somgör from Human Resources
nah i have a reverse proxy ready i did it before with api.mydomain and service.mydomain but thanks
Hackmagician
Hackmagician13mo ago
no problem
Somgör from Human Resources
actually 5000 is still bound to service ill try to just ping that endpoint yes
Hackmagician
Hackmagician13mo ago
works?
Hackmagician
Hackmagician13mo ago
there ya go no problem
Somgör from Human Resources
SCclose glad i switched to nginx apache sucks with reverse proxy
Hackmagician
Hackmagician13mo ago
nginx W
Somgör from Human Resources
fr theres no way im ever gonna use a different webserver again anyways, thanks a lot, i appreciate it so others can see too
Hackmagician
Hackmagician13mo ago
do $close to resolve this
MODiX
MODiX13mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server
More Posts