How to define/create a public IP and use it in NGINX?

Hello,

I want to define Public IP in a machine, and Nginx will be proxy or front of all docker containers who are running in this machine.

Like that i can access to these services by one Public IP .

Thank you

Insofar as “public” IPv4 addresses are not “private” IP addresses, any address which is not in the range of addresses specified in RFC 1918:

 10.0.0.0        -   10.255.255.255  (10/8 prefix)
 172.16.0.0      -   172.31.255.255  (172.16/12 prefix)
 192.168.0.0     -   192.168.255.255 (192.168/16 prefix)

Despite not being being reserved, or private, several other address ranges have special uses, as referenced in the Introduction to RFC 6761.

Now that academic matter has been addressed, I’m left guessing what exactly you are trying to achieve, and hence what might be a useful answer to your question.

My first guess is that your containers are all running in networks isolated on the host, possibly with ports exposed on the host, and that you want to do the right thing and access these services by names, all of which resolve to an IP address on the host with a reverse proxy listening on that address and directing requests to the contained services with proxy_pass to the address(es) and ports (and maybe relaying responses from that address).

How close was this first guess?

1 Like

As a small addendum to what @AJCxZ0 said, if by public IP you mean you want an IP you can reach out from outside your network, you would need to either get a static public IP from your network provider or use a dynamic DNS service by one of the many cloud providers out there.

Thank you, @alessandro, for mentioning that most important detail which I overlooked.

A more modern and sometimes better option for access to local resources from the Internet is to use a tunnel from the local network to a public cloud service. One of several no-cost examples is Cloudflare’s tunnel, which is included Cloudflare’s free plan. This effectively provides a reverse proxy which communicates over a persistent connection which you initiate from the server.

Caveat: I’ve not used any Cloudflare services and have no particular relationship to Cloudflare. I mention them only as a well-known example.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.