title: Connection Refused On Internal IP Address
body: <p>I have a Raspberry Pi set up with nginx to run my dotnet core web api on port 5000. I don't have a firewall on the Pi and I've disabled SSL redirection so running a GET request using telnet as such:</p>
  <pre><code>telnet localhost 5000
  GET /api/test HTTP/1.1
  host: localhost 
  </code></pre>
  <p>works as intended. My problem is that this same approach does not work when using the internal ip address of the machine like <code>telnet 192.168.1.10 5000</code>. Instead I get:</p>
  <pre><code>telnet: Unable to connect to remote host: Connection refused 
  </code></pre>
  <p>I have nginx set up as a reverse proxy to also serve my website. Here's my nginx.conf:</p>
  <pre><code>user www-data;
  work_processes auto;
  pid /run/nginx.pid;
  include /etc/nginx/modules-enabled/*.conf;
  
  events {
      worker_connections 768;
  }
  
  http {
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
      
      ssl_protocols TLSv1 TLSv.1.1 TLSv1.2 
      ssl_prefer_server_ciphers on;
  
      acces_log /var/log/nginx/access.log;
      error_log /var/nginx/error.log;
  
      gzip on;
      
      include /etc/nginx/conf.d/*.conf;
      include /etc/nginx/sites-enabled/*;
  }
  </code></pre>
  <p>And here is my server configuration in sites-enabled:</p>
  <pre><code>server {
      listen 80 default_server;
      server_name mywebsite.com www.mywebsite.com;
      root /srv/www/mywebsite.com;
      index index.html;
  
      location /api {
          proxy_pass      http://localhost:5000;
          proxy_http_version  1.1;
          proxy_set_header    Connection keep-alive;
      }
  }
  </code></pre>
  <p>Why am I not able to connect to the same machine via it's internal IP if I can connect just fine via localhost?</p>
  <p>ANSWER:
  By checking the ports with <code>netstat -tulpn | grep LISTEN</code> I saw that my dotnet application was listening only on 127.0.0.1:5000 instead of on all IP addresses. To make the application listen on all IP addresses, I set the host builder's <code>UseUrls()</code> in the application's <code>Program.cs</code> file:</p>
  <pre><code>public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
              Host.CreateDefaultBuilder(args)
                  .ConfigureWebHostDefaults(webBuilder =&gt;
                  {
                      webBuilder.UseStartup&lt;Startup&gt;();
                      webBuilder.UseUrls(urls: new String[] { &quot;http://*:5000&quot;, &quot;https://localhost:5001&quot; });
                  });
  </code></pre>
  <p>I couldn't get the <code>appsettings.json</code> file to have any effect but this one works and I can now access the api from it's internal IP address.</p>