✅ 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
The Fog from Human Resources
(I haven't worked with ASP.NET in a good while so im unsure of what to do)
Hackmagician
Hackmagician2y 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?
The Fog 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
Hackmagician2y 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
The Fog 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
The Fog 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
Hackmagician2y 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
The Fog 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
The Fog from Human Resources
ill check
Hackmagician
Hackmagician2y ago
What host is the one that the server says it's listening on?
The Fog from Human Resources
localhost:5000
Hackmagician
Hackmagician2y ago
Have you tried to run this same command on your server to check if it responds?
The Fog from Human Resources
for example this one just works
The Fog from Human Resources
ill check
Hackmagician
Hackmagician2y 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
The Fog from Human Resources
ill try to set a reverse proxy maybe its rly the fix
Hackmagician
Hackmagician2y 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
The Fog from Human Resources
nah i have a reverse proxy ready i did it before with api.mydomain and service.mydomain but thanks
Hackmagician
Hackmagician2y ago
no problem
The Fog from Human Resources
actually 5000 is still bound to service ill try to just ping that endpoint yes
Hackmagician
Hackmagician2y ago
works?
Hackmagician
Hackmagician2y ago
there ya go no problem
The Fog from Human Resources
SCclose glad i switched to nginx apache sucks with reverse proxy
Hackmagician
Hackmagician2y ago
nginx W
The Fog 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
Hackmagician2y ago
do $close to resolve this
MODiX
MODiX2y ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server