# Source: https://docs.replit.com/replit-workspace/ports.md

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.replit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Ports

> Learn how ports work in Replit's cloud environment, including port forwarding, configuration, and troubleshooting for your web applications.

Because Replit runs your projects on a cloud environment, ports work differently on Replit than on your local computer. (If you need a more basic explanation of what TCP ports are, [start here](https://www.reddit.com/r/explainlikeimfive/comments/1t9s5a/eli5_what_are_ports_ex_tcp_port/).)

On a computer, you only have one layer of port management: your programs define a port that they listen to, and when traffic hits that port on your computer from the internet, they get routed to the appropriate process.

<Frame>
  <img src="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer.png?fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=6e8edcd0ec3e450bdef6c32289d36dcc" alt="computer" data-og-width="1323" width="1323" data-og-height="786" height="786" data-path="images/ports/computer.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer.png?w=280&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=775a3de2db956e4264f70045b89132ec 280w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer.png?w=560&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=20c69209a928d246c9860cd3ba8fca82 560w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer.png?w=840&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=66641ba16e214329b32a0551b93ca1ae 840w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer.png?w=1100&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=17658710b99e4be60650126286ad4e39 1100w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer.png?w=1650&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=0aafbe410d2a1f13a3007c608f5d15e1 1650w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer.png?w=2500&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=a86b6b824760fd2a32b59cc160d1978e 2500w" />
</Frame>

The `0.0.0.0` part is the address, or host. If a process is listening on `0.0.0.0`, that means it should listen on every network interface — which means that if another computer (on the internet) sends a request to your computer’s IP address, it will see it. So, listening on 0.0.0.0 means those processes are accessible to the public internet (if your computer is connected.)

Most programming frameworks will *not* listen on `0.0.0.0` when you’re developing, because you don’t necessarily want your work exposed to the public while you’re working on it, for privacy & security. Instead, they’ll listen on a different address — `127.0.0.1`, otherwise known as `localhost`. This means only that computer can make requests to that port.

<Frame>
  <img src="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer-localhost.png?fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=96a818c90fd879a814a647e18b506f7c" alt="Localhost ports are only visible on the computer that is hosting them." data-og-width="1467" width="1467" data-og-height="786" height="786" data-path="images/ports/computer-localhost.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer-localhost.png?w=280&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=6c1101c44eca3258a3af58c87e003383 280w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer-localhost.png?w=560&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=c2b2abbe28febfaf3a91e924a9511487 560w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer-localhost.png?w=840&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=17b8541476279f5059c46b2795bc4813 840w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer-localhost.png?w=1100&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=d35bcf26549c31a9557dd98303c43a70 1100w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer-localhost.png?w=1650&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=7402d56816b47e6aa8a9c464f2d85a81 1650w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/computer-localhost.png?w=2500&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=e7488daecf3e9b27d01b05dea4691050 2500w" />
</Frame>

On Replit, for a process you’re running to be accessible in the webview or via an external request, it has to have an **external port** defined. This is because the “internal port” that processes typically use is only visible from inside the sandboxed cloud environment that Replit provides. We have to connect that internal port to an externally accessible port to send the right traffic to your programs. Even if your process listens on a port typically available to the public like 0.0.0.0, we still need to bind that port to an external port.

<Frame>
  <img src="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit.png?fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=9162e125c12faa1b6f896cc394957a85" alt="External ports forward traffic to internal ports, which programs listen to." data-og-width="1641" width="1641" data-og-height="870" height="870" data-path="images/ports/replit.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit.png?w=280&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=9847294d5162631968e3534dab7ffdd4 280w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit.png?w=560&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=3f0b3be4610bf04d65f285544c9a335e 560w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit.png?w=840&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=ea8f65debfd86b6eb5baf35bb2ef79f4 840w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit.png?w=1100&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=5c916076a6d73e356219ac2be60afbdb 1100w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit.png?w=1650&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=07faaf5a86908493317d8a475c7c822f 1650w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit.png?w=2500&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=d932c004b08f398793ea1966931479b1 2500w" />
</Frame>

We do this by binding external ports to specific internal ports — for example, in the diagram above, the external port `:80` is bound to the internal port `:3000`. That means any traffic that Replit App gets on port 80 will go to the internal port 3000.

This configuration is captured in the \[\[ports]] section of the .replit config file.

By default, we will bind the first port you open to the default external port 80, which will allow that process to be available at the domain without a port address (e.g. customdomain.com/ instead of customdomain.com:3000/). Additional internal ports that are opened will be bound to other available external ports (see a full list below.)

## Preview

In the Preview tool, you can change which external port the webview is rendering by clicking the domain and selecting a different port. You can also open the networking tool from the “gear” icon for more details.

<Frame>
  <img src="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/webview_dropdown.png?fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=35f188e6a98287c45e1c5a4b811e9794" alt="Clicking the domain in the webview will let you choose what port to view." data-og-width="862" width="862" data-og-height="534" height="534" data-path="images/ports/webview_dropdown.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/webview_dropdown.png?w=280&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=4cab25810ceb8f1125c30bcddd4f5d32 280w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/webview_dropdown.png?w=560&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=fc6ffd9fa846d688df547b3805884d8c 560w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/webview_dropdown.png?w=840&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=7dbf42718ac2e593cd5315efc383a857 840w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/webview_dropdown.png?w=1100&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=805763650e84cc73e60f19bd25738ad6 1100w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/webview_dropdown.png?w=1650&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=89340d50a74da48903c39549b1b3d628 1650w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/webview_dropdown.png?w=2500&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=22887dd79832ab8bce7acb3e40124ffa 2500w" />
</Frame>

## Default port

Port :80 is the “default port” for http traffic, so http traffic sent to the root domain will automatically be routed to port 80. We don’t show the port path in the url for port 80 for that reason. Ports other than :`80` will show up in the domain path (e.g. customdomain.com:4200/). (We provide TLS by default, so it will technically be over port 443, which is the default port for https. For all intents and purposes, you can treat them as interchangeable.)

## Networking tool

For more details about port config and networking, you can open the networking tool. It shows the status of ports open in your Replit App, what external port they’re bound to, and lets you add or remove configuration.

<Frame>
  <img src="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/networking_tool.png?fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=61b24a896e5dc920ed70f3603228d33f" alt="The networking tool shows your port configuration." data-og-width="1412" width="1412" data-og-height="558" height="558" data-path="images/ports/networking_tool.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/networking_tool.png?w=280&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=7758f058badd546ee17dffe23b5d7602 280w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/networking_tool.png?w=560&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=b28b2277982aa85603a5b152b529c795 560w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/networking_tool.png?w=840&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=a1d9a74958d98792d5c0559b10a04b71 840w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/networking_tool.png?w=1100&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=a7e2f1c68bf11efb8524fcaaac5bfa0e 1100w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/networking_tool.png?w=1650&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=111bed8b10c514a0bd32d0d6f925896b 1650w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/networking_tool.png?w=2500&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=c7ced17234877b314f25a8b36f835cd4 2500w" />
</Frame>

## Publishing

Autoscale and Reserved VM deployments only support a single external port being exposed, and for the corresponding internal port not to be using `localhost`. If you expose more ports, or expose a single port on localhost, your published app will fail. An easy way to make sure your Autoscale deployments work as expected is to remove all the `externalPort` entries for the ports in your config *except* the port for the service you want to interact with from the internet.

## Debugging

A common reason something might not be working as you’d expect is that while your port config looks right, your program is actually looking at a different port. For example, if your config is:

```
[[ports]]
internalPort = 3000
externalPort = 80
```

Then internet traffic to port 80 will go to internal port 3000. However, if your program is actually not listening on port 3000, but rather something else (like 8080), it will appear as if no traffic is getting through. This can happen if you switch the port in your code without switching the corresponding port in your config, or copy-paste config from one project to another.

<Frame>
  <img src="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit-wrong_port.png?fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=42510d0331118fcf4a5cba7c812d09ee" alt="Programs can change the ports they listen to." data-og-width="1641" width="1641" data-og-height="870" height="870" data-path="images/ports/replit-wrong_port.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit-wrong_port.png?w=280&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=19c3088d254e9165fc714ae3497816c7 280w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit-wrong_port.png?w=560&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=e28fd389256d15f407d9d547e5cbfe61 560w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit-wrong_port.png?w=840&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=3f4affcd9b5a5002295d7b47c61ca8d0 840w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit-wrong_port.png?w=1100&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=4ec70b27e624e42e6b5893fd6282ce2e 1100w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit-wrong_port.png?w=1650&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=37336bfba670380afbfb13da73446db6 1650w, https://mintcdn.com/replit/AZ1L8RlIroSxuJDa/images/ports/replit-wrong_port.png?w=2500&fit=max&auto=format&n=AZ1L8RlIroSxuJDa&q=85&s=1bb4ea08f4a6066c533d5ad1ad6f001e 2500w" />
</Frame>

Each framework has different default ports it listens to — for example, Flask is 5000, react is 3000, and laravel is 8000. Make sure the right port is configured!

## Preferences

We will automatically bind ports that are opened in your Replit App to available external ports when they are opened, and record that binding in the .replit config file.

However, we don’t do this by default for internal ports that open on localhost, because services that usually run on localhost typically assume that they will only be accessible on the same computer as the process that’s running (localhost ports are only visible to the same computer running the process.) This means those services are often not as secure as services built under the assumption that they’ll be available to the public internet.

You can always override this by setting the `exposeLocalhost` config option to `true` for the port you want to expose.

If you want to *always* expose localhost ports by default, you can set your “automatic port forwarding” setting in the User Settings tool to “All ports”.

If you want to *never* create config for ports that are opened, and manually control the port config for all your Replit App, you can set that to “never”.

## Supported ports

Replit App will define port 80 as the external port by default when the first port opens. A Replit App can expose 3000, 3001, 3002, 3003, 4200, 5000, 5173, 6000, 6800, 8000, 8008, 8080, 8081, as extra external ports.

Ports 22 and 8283 are not forwardable, as they are used internally.

## `[[ports]]` .replit config

Type: `{localPort, externalPort, exposeLocalhost}`

The `[[ports]]` config Allows you to configure which HTTP port to expose for your web output. By default, any exposed HTTP port with host 0.0.0.0 will be exposed as your Replit App's web output.

Extra ports can be served without overriding the default port by adding a new \[\[ports]] entry to your .replit file. You are required to specify both a localPort and externalPort entry. You can add multiple extra ports by adding multiple \[\[ports]] entries to your .replit file as defined below.

### localPort

Determines which port Replit will bind to an external port.

### externalPort

Determines which port should be exposed for that local port’s publicly accessible port.

```toml  theme={null}
[[ports]]
localPort = 3000
externalPort = 80
```

If you want to *never* expose a particular port, you can leave the `localPort` config but just not add an `externalPort`:

```toml  theme={null}
[[ports]]
localPort = 3000
```

### exposeLocalhost

Determines whether an internal port using `localhost` can be bound to an external port. Can be `true`, `false`, or null.

```toml  theme={null}
[[ports]]
localPort = 3000
externalPort = 80
exposeLocalhost = true
```