Remote API Access RRS feed

  • Question

  • User311243799 posted

    Hi all, I have a net core 3.1 WebAPI service running on a Linux box on my local LAN as a daemon and it all works as expected.

    How can I expose the service so it is available outside my Lan ?

    What I've done

    Forwarded the listening port on my router to the local ip and port on my Lan where the WebAPI resides.

    Result when calling a controller method
    404 not found, the API is using Nginx as a reverse proxy

    Please let me know if I haven't supplied enough information

    Tuesday, April 21, 2020 6:49 AM

All replies

  • User415553908 posted

    It appears you've got Nginx fronting your API - the config file is probably relevant. Do you run your API in Docker? Then command line/docker-compose.yml contents will also probably be helpful.

    Then it's a bit hard to say if your router/ISP also have a role in it

    Wednesday, April 22, 2020 1:24 PM
  • User-474980206 posted

    Check that the port is open on the routers firewall. Also check that your isp is nor nat translating.  From in your network Google what is my IP address to get your real ipaddress. This is the ipaddress you should use to test your port forwarding.

    note: if nat translated, it will change over time. There are programs you can install that will give this address externally.

    Wednesday, April 22, 2020 2:13 PM
  • User311243799 posted

    Hi there no I don't use Docker. This is the conf file from the /etc/nginx/sites-enabled folder

    server {
    listen 80;
    listen [::]:80;

    access_log /var/log/nginx/reverse-access.log;
    error_log /var/log/nginx/reverse-error.log;

    location / {

    as I said it works fine locally

    Wednesday, April 22, 2020 2:47 PM
  • User311243799 posted

    Hi there, I opened port 9654 and forwarded it to my API machine ( I do this sort of thing a lot just never with net core ) My ASUS router gives me a public DNS name ( again I use this all the time )

    Wednesday, April 22, 2020 2:50 PM
  • User-474980206 posted

     your ngnix proxy is listening on port 80, is this where you forwarded to?

    Wednesday, April 22, 2020 7:53 PM
  • User415553908 posted

    Now that i think of it..if your Nginx responds with 404 - it is reachable from over the Internet and it means your router and ISP are not a problem.

    It's a bit hard to troubleshoot this without knowing your LAN topology. Looking at your IP address I suspect you've got Nginx sitting on another machine (you probably won't bother with class A address space if you only had a handful of hosts on the network, right?).

    Are you able to check if all hosts involved on the LAN have correct firewall rules and are bound to correct network interfaces?

    Wednesday, April 22, 2020 7:57 PM
  • User311243799 posted

    It listens on port 80 on the machine it's running on - the nginx proxy forwards the request to my API port 9654 in this case

    Wednesday, April 22, 2020 8:21 PM
  • User311243799 posted

    Bruce you nailed it I changed my router to forward to port 80 and bingo it worked - I thought nginx would pick up a request to 9654 - thank you very much

    Wednesday, April 22, 2020 8:29 PM
  • User-474980206 posted

    In the ngnix, the listen parameter says what port ngnix listens on. You probable the asp.net port blocked externally on the Linux box, or ngnix would have been bypassed.

    Wednesday, April 22, 2020 11:50 PM