How to make your local app accessible to your network?

By Prajwal Haniya

Techletter #97 | November 02, 2024

Deploying the app and making it accessible within your network is something interesting that I have done few weeks back. This is something that I learned out of frustration to save cost for deployment. Due to this issue, I learned how you can deploy your app locally and act your machine as a server.

This is not only for your network but also you can use this techinque to deploy your app with a domain name on aws ec2 instance.

I have used nginx to achieve this.

I believe that you already have a nodejs or python app running. Now you can use nginx to redirect the requests from your network to the specific app. If you don’t know what the nginx is, then you can learn about it here.

How to locate nginx configuration file?

nginx -t

Go to nginx.conf , add the below configuration (Or the configuration as required by you)

work_processes 1;

events {
    worker_connections  1024;
}

http {
	include mime.types;
	default_type application/octet-stream;
	
	server {
		listen 8080;
		server_name YOUR_IP_ADDRESS;
		
		location /api {
				proxy_pass http://localhost:3000/app;
				proxy_set_header Host $host;
				proxy_set_header X-Real-IP $remote_addr;
	      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	      proxy_set_header X-Forwarded-Proto $scheme;
		}
	}
}

Once you have this configured, just start the nginx server with the below command:

brew services start nginx

After you trying this, believe me you will definitely fall in love with software engineering in general. Because, it is just beautiful. I know this is just a simple one, but using this you can actually deploy large scale application without any issues.