Default Server
NGINX and IP Addresses
When NGINX is set to listen on a port (like port 80 in your default server block), it can be configured to listen on all network interfaces or a specific IP address. If no IP is specified, NGINX listens on all available interfaces (0.0.0.0 for IPv4 or :: for IPv6), which means it can accept connections from any IP address that can route to it, including local and external traffic.
For instance, your default server block:
server {
listen 80 default_server;
server_name _;
root /var/www/html;
location / {
return 200 'NGINX Default Response. Server is running.';
}
}
This configuration listens on port 80 for all network interfaces
(default_server makes it the default for any unmatched domain names).
Public vs. Local IP
Public IP: The IP address assigned to you by your internet service provider (ISP), visible to the outside world. If you want your NGINX server accessible from the internet, you would typically configure your router to forward the desired ports (like 80 for HTTP) from your public IP to the local IP of the server running NGINX. This is known as NAT (Network Address Translation).
Local IP: Addresses assigned to machines within your local network. They are not accessible from the internet without configuration on your network router (port forwarding).
Testing NGINX Locally
If you access "localhost" or "127.0.0.1" in your browser, you are making requests to your local machine. If NGINX is configured to listen on all interfaces, it will respond to requests coming from local processes directly to the IP of the machine or through the loopback interface.
Setting Up for Internet Access
To make your NGINX server accessible from the internet:
Static Public IP: Ensure your ISP has provided a static public IP.
Port Forwarding: Configure your router to forward HTTP (port 80) and HTTPS (port 443) traffic to the local IP of the machine running NGINX.
Firewall Rules: Adjust your firewall settings on both your router and the server to allow traffic on these ports.
Dynamic DNS: If you do not have a static IP, use a Dynamic DNS service that updates your domain's DNS records to point to your changing IP address.