Home / Blog / Web Development

Web Development

Angular ng serve Not Working on EC2? Fix 'Provided Host Could Not Be Bound' (2026)

ng serve works locally but fails on EC2? Here is why the host cannot be bound, how to fix it safely, and how to deploy the app properly with Nginx.

In this article
  1. The problem
  2. Which error
  3. Why it happens
  4. Step-by-step fix
  5. Still not loading
  6. Host not allowed
  7. Security warning
  8. Keep it running
  9. Deploy with Nginx
  10. Docker
  11. Need help?
  12. Frequently asked questions

If ng serve fails on an AWS EC2 instance with "Provided host could NOT be bound", or the app starts but the browser cannot reach it, the cause is almost always how EC2 handles public and private IP addresses. This guide shows the fix, the checks to run when it still does not load, and how to deploy the app properly with Nginx.

Key takeaways

  • Use ng serve --host 0.0.0.0 instead of the public IP or DNS name.
  • Open the port in your Security Group for your own IP only, never for the whole internet.
  • Newer Angular versions may also need --allowed-hosts when you use a hostname.
  • ng serve is for development. Deploy production builds with Nginx or S3 and CloudFront.

The problem

You start your Angular app on an AWS EC2 instance and see this:

Provided host xx.xx.xx.xx could NOT be bound. Please provide a different host address or hostname

Or the server starts, but the browser shows a timeout, a blank page or a message that the host is not allowed. This confuses many developers new to AWS, because the same command works fine on a local machine.

Which error do you have?

Error or symptomLikely causeFix
Provided host ... could NOT be bound--host was set to the EC2 public IP or public DNS, which isn't an address on the instanceUse --host 0.0.0.0
Browser times out or can't connectSecurity Group, firewall or network ACL blocking the port, or the server listens only on localhostOpen the port for your IP, check ufw, use --host 0.0.0.0
Blocked request. This host is not allowedHost check in newer Angular dev servers when you use a hostnameAdd the hostname with --allowed-hosts (see below)
Invalid Host headerHost check in older, webpack-based dev serversUse --host 0.0.0.0 and the host-check option your version supports
Works, then stops when you close the terminalThe SSH session ended and took the process with itRun it in tmux (see below)

Why this happens: public vs private IP on EC2

An EC2 instance's network interface has only a private IP address, such as 172.31.x.x. The public IP and public DNS name are not configured on the machine itself. AWS translates them to the private IP at the network edge.

When you run ng serve --host <public-DNS>, Angular asks the operating system to listen on an address the machine does not own, so the bind fails with "could NOT be bound".

The fix is to bind to all interfaces with 0.0.0.0. AWS forwards packets sent to your public IP to the instance, and Angular receives them.

Earlier versions of this article suggested using the public DNS name as the host. That can appear to work in some setups, but it is not reliable, which is why 0.0.0.0 is the recommended approach.

Step-by-step fix

Step 1: Allow the port in your Security Group

  • Open the EC2 console, select your instance and open the Security tab.
  • Click the Security Group, then Edit inbound rules.
  • Add a rule: Type Custom TCP, Port range 4200 (or your chosen port), Source My IP.
  • Save the rule.

Using My IP keeps your dev server private. Avoid 0.0.0.0/0 (anywhere), which exposes an unfinished app to the whole internet.

Step 2: Start the dev server on all interfaces

From your project folder on the instance:

ng serve --host 0.0.0.0 --port 4200

Step 3: Check it from the server

Open a second SSH session and run:

curl -I http://localhost:4200
ss -tlnp | grep 4200

The curl command should return an HTTP response, and ss should show Node listening on 0.0.0.0:4200. If both work, the app is fine and any remaining problem is in the network path.

Step 4: Open it in your browser

Find your instance's Public IPv4 address or Public IPv4 DNS in the EC2 console and visit:

http://<public-ip-or-dns>:4200

Use http, not https. The dev server does not serve HTTPS by default.

If it still doesn't load

Check these in order:

  • OS firewall: on Ubuntu, run sudo ufw status. If it is active, allow the port with sudo ufw allow 4200/tcp.
  • Network ACL: the subnet's network ACL must allow inbound traffic on the port and the return traffic.
  • Public IP: make sure the instance has a public IP, and that its subnet has a route to an internet gateway.
  • Right instance, right region: confirm you are using the public IP of the instance you are logged into.
  • Changing IP: a public IP changes when you stop and start the instance. Attach an Elastic IP if you need a stable address.
  • Port already in use: run ss -tlnp to see whether another process is using the port, or choose another port.

Newer Angular versions: "This host is not allowed"

Current Angular projects use a Vite-based development server. If you open the app through a hostname, such as the EC2 public DNS name or your own domain, the server may reject the request with "Blocked request. This host is not allowed."

Allow the hostname when you start the server:

ng serve --host 0.0.0.0 --port 4200 --allowed-hosts your-hostname.example.com

Or set it permanently in angular.json, under your project's serve options:

"serve": {
  "options": {
    "host": "0.0.0.0",
    "port": 4200,
    "allowedHosts": ["your-hostname.example.com"]
  }
}

Option names can differ between Angular versions, so run ng serve --help to confirm what your version supports.

Some suggestions online recommend --disable-host-check. That option belongs to the older webpack dev server, does not exist in newer versions, and turns off a security feature, so avoid it.

If you run behind a proxy or load balancer, look at the --public-host option too.

Security warning: ng serve is for development only

ng serve runs a development server with live reload. It is not built to handle production traffic or hostile networks.

  • Do not expose the port to 0.0.0.0/0. Restrict it to your own IP, or use an SSH tunnel such as ssh -L 4200:localhost:4200 user@your-server and open localhost:4200 on your own machine.
  • Do not use ng serve in production. It is slower, less secure and has no HTTPS.
  • Keep Security Groups strict and close ports you do not need.

Keep the dev server running

If ng serve stops whenever you close your SSH window, run it inside tmux:

tmux new -s angular
ng serve --host 0.0.0.0 --port 4200

Press Ctrl+B, then D to detach. Re-attach later with tmux attach -t angular. For anything longer-lived than a dev session, deploy properly as shown next.

Do it properly: deploy with Nginx

On a real website, build the app once and let a web server serve the static files. The commands below are for Ubuntu. Amazon Linux uses dnf instead of apt.

1. Build the app:

ng build --configuration production

The output goes to dist/<your-project> or, in recent Angular versions, dist/<your-project>/browser. Check your folder to be sure.

2. Install Nginx and copy the files:

sudo apt update
sudo apt install nginx
sudo mkdir -p /var/www/my-app
sudo cp -r dist/<your-project>/browser/* /var/www/my-app/

3. Configure Nginx in /etc/nginx/sites-available/my-app:

server {
    listen 80;
    server_name your-domain.com;
    root /var/www/my-app;
    index index.html;

    location / {
        try_files $uri $uri/ /index.html;
    }
}

The try_files line sends unknown paths to index.html, which Angular's router needs so that deep links and page refreshes work.

4. Enable the site and reload:

sudo ln -s /etc/nginx/sites-available/my-app /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

5. Open ports 80 and 443 in the Security Group, and add HTTPS with a free Let's Encrypt certificate:

sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com

This assumes your domain's DNS already points to the instance's Elastic IP.

Alternative: for a static app you can host the build on Amazon S3 with CloudFront, which removes the need to manage a server. A server-side rendered app needs a Node server.

Using Docker or dev containers?

The same rule applies in containers: the dev server must listen on 0.0.0.0 or it cannot be reached from outside the container. Use the same --host 0.0.0.0 flag in your Dockerfile or Compose file, and publish the port (for example -p 4200:4200).

Need help with AWS hosting or deployment?

Secure, reliable hosting on AWS takes more than getting ng serve to run. Networking, HTTPS, backups, monitoring and cost control all matter. Ucodice can deploy and manage your Angular and backend applications on AWS.

Talk to our server support team | Hire Angular developers | Contact us

Frequently asked questions

Why can't I use my EC2 public DNS as the host?

The public DNS name is not assigned to the machine. It belongs to AWS's network layer, which forwards traffic to your private IP. Angular can only bind to addresses the machine owns, so use 0.0.0.0.

Is --host 0.0.0.0 safe?

It only means the server listens on all network interfaces of that machine. Whether the outside world can reach it depends on your Security Group and firewall. Keep the inbound rule limited to your own IP.

Can I run my production site with ng serve?

No. Use ng build, then serve the output with Nginx or S3 and CloudFront.

Why does the page load by IP address but not by hostname?

Newer Angular dev servers check the hostname of every request. Add your hostname with --allowed-hosts, or with allowedHosts in angular.json.

Which port should I use?

Any free port works. 4200 is Angular's default. Whatever you choose, the --port value must match your Security Group rule.

Why does my app stop when I close SSH?

The process ends with the session. Use tmux for development. For production, deploy with Nginx so you do not need ng serve at all.

The Ucodice Team is a group of passionate developers, designers and strategists delivering web, mobile and software solutions to clients worldwide.

Ready to take the next step?

Explore our web development services or tell us about your project. A senior member of our team will get back to you with clear next steps.

Let's start your project

Tell us what you want to build or grow. We'll reply within one business day with clear next steps.

Phone: 9560430495  ·  Email: contact@ucodice.com

Office: Ucodice Technologies, IHDP Business Park, Street Number 7, Sector 127, Noida, Uttar Pradesh 201304. Also serving Delhi NCR and clients worldwide.

Trusted and certified

  • Google PartnerCertified for Google Ads
  • Meta business PartnerCertified for Meta Ads
  • 4.3 / 5 on Google47 Google reviews
  • 4.9 / 5 on Freelancer.in245 reviews

Free consultation

Tell us about your project.

Get a free quote