setting up a web stack with nginx? - nginx

I have got a dedicated server that has nginx web server located in a uk datacenter, the ngnix acts as a front end server which then directs users to other instances that i have on aws located in america. What ip address would the client see, the ngnix front server(which is the desired result), or would the client still know about the instances or servers ip address located in america?
PS. nginx acts as a load balancer here.

Typically, users connect to "www.yoursite.com", and that gets looked up in DNS.
Assuming there is only one DNS entry (corresponding your nginx frontend), then as far as those users are concerned, they are only talking to that one machine.
Sometimes people use round-robin DNS, where multiple machines correspond to a given host name.
Presumably you would know if you were doing this, though (:
You can confirm this by tracing your traffic when connecting. Maybe use WireShark?

Related

Redirecting minecraft port to another

We are transferring our Minecraft server to a different host and there's a pretty good chance, that it will be running on a different port.
I currently have two records on the server website:
mc.domain.sk CNAME {ServerIP}
_minecraft._tcp.mc.domain.sk SRV 5 25560 mc.domain.sk
So just changing the port in the SRV record should be fine. But here's the catch - many players have been connecting to our server using the port too. Basically using mc.domain.sk:25560 instead of just mc.domain.sk. Is there any way to forward this 25560 port to another port (f.e. 25561)?
First of all, CNAME must NOT point to an IP. It must point to another domain name, so unless you mis-wrote the question, your setup is incorrect.
Is there any way to forward this 25560 port to another port?
Is any downtime acceptable? If yes, then it's easy just spawn a proxy (nginx) at that domain and that port, and redirect all incoming traffic to another domain and another port.
If downtime is not acceptable, then you need somehow to migrate active connections between hosts. Even if you manage to do this at IP/TCP level, I don't know if your application will be able to handle this correctly. Cannot help on that.

Google router IP vs Google public IP

I am trying to get the big picture although my primary domain is not networking.
Some question's narrowed down for which I'm not getting enough/proper answers online
Is the IP that is resolved by the DNS server when I hit www.google.com is same as any of the Google router's Gateway IP?
Do bigger companies like Amazon do port forwarding?
If point 2 is true, I suppose they must be port forwarding with only 443 (https) port which means, to use multiple static IP across different data centers, they need to have that many routers. So, if they have N static IP address which resolves to a website, then they must be having N routers right? Is this a fair assumption?
A gateway IP refers to a device on a network which sends local
network traffic to other networks. it sits between you and internet,or other network . its like a watchman.
Question 1 : google.com has multiple ip addresses lets say then , Yes, that is possible, and will need to be two A records. This is called Round-Robin DNS. Clients will semi-randomly use one of the two addresses.
question2: yes port forwarding happens more often than we think. ALL VPC's (virtual private clouds like AWS , GCP , Azure etc) use this as they dont want to expose servers/internal resources to the internet.
depending on the port number , particular service is exposed to requesting client. lets say we want to make a website public , then we explicitly expose port 80(http) 443(https) so that web crawlers and users can see them.
Port forwarding, sometimes called port mapping, allows computers or
services in private networks to connect over the internet with other
public or private computers or services.
google https://www.google.com:444/ wont work because they did not expose port 444 on their cloud router
but https://www.google.com:443/ will work because the server corresponding to google.com has explicitly left it open.
How IP is resolved:
Step 1 - Send a Request to Resolve a Domain Name
When you type www.google.com into a browser, in order to load the webpage, your computer asks for the IP address. Computers do not know in advance where they can find the necessary information, so they try searching through the DNS cache and for available external source. proceed from lower level caches to root/main servers.
Step 2+3 - Try to resolve an IP Locally
Before going externally, your computer loads the local DNS cache database to see if you already requested the IP for that domain name. Every computer has a temporary cache with the most recent DNS requests and attempts to connect to online sources. if required record is present locally its called "CACHE HIT" and query stops.
However A computer’s local DNS cache database does not always contain the necessary data to resolve a domain name this is called a "CACHE MISS" . In that case, the request goes further to your Internet Service Provider (ISP) and its DNS server.
Step 4 - ISPs Ask Outside DNS Servers to Provide an IP Address iff Cache miss
ISP DNS resolvers are configured to ask other DNS servers for correct IP address mapping until they can provide data back to the requester. These are iterative DNS queries.
When a DNS client sends such a request, the first responding server does not provide the needed IP address. Instead, it directs the request to another server that is lower in the DNS hierarchy, and that one to another until the IP address is fully resolved. There are a few stops in this process.
hierarchy looks like this (just for reference):
Root domain nameservers. Root servers themselves do not map IP addresses to domain names. Instead, they hold the information about all top-level domain (TLD) nameservers and point to their location. TLD is the rightmost section of a domain name... Root servers are critical since they are the first stop for all DNS lookup requests.
TLD nameservers. These servers contain the data for second-level domains, such as ‘phoenixnap’ in phoenixnap.com. Previously, the root server pointed to the location of the TLD server. Then, the TLD server needs to direct the request toward the server that contains the necessary data for the website we are trying to reach.
Authoritative nameserver. Authoritative servers are the final destination for DNS lookup requests. They provide the website’s IP address back to the recursive DNS servers. If the site has subdomains, the local DNS server will keep sending requests to the authoritative server until it finally resolves the IP address.
Step 5 - Receive the IP Address
Once the ISP’s recursive DNS server obtains the IP address by sending multiple iterative DNS queries, it finally returns it to your computer. The record for this request now stays cached on the hard drive. The browser can then fetch this IP from the cache and connect it to the website’s server.
ALL this happens in less than 1 second, most of the times. if you just registered a new domain it might take few hours to propagate this DNS cache globally hence newly registered websites do not show up sometimes.
About companies owning multiple IPs
Big companies have pool of IPs reserved for example 123.234.xxx.xxx which means a company has reserved 255*255 ips. they are mapped on a VPC(virtual private cloud)
and accessible vis a subnet masking and CIDR feature, like your EC2 instances on AWS
Is the IP that is resolved by the DNS server when I hit www.google.com is same as any of the Google router's Gateway IP?
For sure it should, but it is mostly a Google management question that only they will be able to answer right. The thing is that we must understand how DNS query's work for this.
Let's take a look of it:
Device A requests the IP address through a DNS query of the device B.
To do this, it uses the network port 53 (Domain) on which it will ask, depending on which DNS server is being used at the time, which is usually the home router. Then the router will ask the ISP's DNS server, which will respond with a cached response, or the query with another server on top of it if it does not have one; All this process is followed until a reliable cache response is reached or until the authoritative response server is reached, that is, the name server that manages the domain in question.
Only the authoritative response server contains the reliable information of which IP of the domain which is going to be reached.
I suppose that within Google's servers and its network they use Google's own DNS servers, which are 8.8.8.8 and 8.8.4.4 where the DNS records are obtained and consulted by caching from many sites.
In general terms Google's IP will change depending on where you are, I made a DIG query to Google's authoritative servers, however, I received a result based on location to improve the route and loading time of the site which was 142.250.73.238.
Do bigger companies like Amazon do port forwarding?
Yes, they do. To handle queries with load balancers or similar and even for caching dns requests.
If point 2 is true, I suppose they must be port forwarding with only 443 (https) port which means, to use multiple static IP across different data centers, they need to have that many routers. So, if they have N static IP address which resolves to a website, then they must be having N routers right? Is this a fair assumption?
This has multiple answers. By the way, they actually can do a secure DNS query.
if they have N static IP address which resolves to a website, then they must be having N routers right?
They don't have to, but if they want to they can.
"Is this a fair assumption?"
No, the IP's doesn't depend on a router, the router only routes to a computer/server which can have multiple IP's. By the other hand, each thing (computer, server, etc... must have an IP which can be also a WAN IP).

DNS Server IP Address

I have a basic question about DNS infrastructure.
I'm wondering how the IP addresses of upstream DNS servers are configured within DNS servers. For example, when my router needs to satisfy a DNS query on behalf of a machine on my LAN, it asks its upstream DNS server that it was given through DHCP. However, how does the upstream DNS server know how to reach the root DNS server or some authoritative DNS server if it doesn't have that information cached? Is the root DNS server's IP address hardcoded anywhere to achieve this? Are backbone DNS servers always configured with some DNS server upstream from it?
I recall setting up a Microsoft DNS server in which any requests that couldn't be satisfied by it would be forwarded. However, since an upstream DNS server wasn't configured, it forwarded those requests right to the root. This behavior makes sense, however, how did it know where to contact the root?
Your reasoning is correct.
Q: How does the upstream DNS server know how to reach the root DNS server or some authoritative DNS server if it doesn't have that information cached? Is the root DNS server's IP address hardcoded anywhere to achieve this?
A: Small scale DNS server (for example DNS server serving clients in one organization) will sometimes have (manually) configured forwarders (usually ISP nameservers) in order to benefit from big cache of ISPs nameservers and faster queries. From my experience, with faster internet links (and with less latency) in recent years, this setup is used less often. Instead, root hints are used.
Q: Is the root DNS server's IP address hardcoded anywhere to achieve this?
A: Yes. For Microsoft DNS server it is located in systemroot\System32\dns\cache.dns, for BIND it is usually in /etc/bind/db.root or /var/named/named.root. An updated copy (if needed) can be retrieved from https://www.internic.net/domain/db.cache
Q: Are backbone DNS servers always configured with some DNS server upstream from it?
A: As far as I know, never.
A recursive server has the (or at least a) list of root servers provided out-of-band. This is often called "root hints" or something similar. Once it knows how to talk to the root servers, everything else follows from that. In practice, a recursor will quite quickly come to cache the name server addresses for the more common TLDs (like .COM and .ORG), so it doesn't always have to start at the root. But the root server addresses are manually provided to start things off.

DNS records for http web servers behind NAT with different external ports

So basically.
I have one external IP.
I am running few web servers on my internal network.
All web servers are configured in NAT with different ports (80,81,82,...)
My domain's DNS is configured on my external IP. And NAT forwards it to my first web server.
Until now when I open my domain let's say example.com it opens my first web server's page.
When I open example.com:81 it opens second server, etc..
What I am trying to achieve is some way to open my other web servers on different sub-domains without specifying port.
So I would like to have something like:
second.example.com -> example.com:81
third.example.com -> example.com:82
I am using SRV record for my TeamSpeak3 server, so my TS3 is running on port 2222 and SRV record translates my ts3.example.com to example.com:2222 and it works like a charm.
Can those sub-domains be configured by SRV records in DNS?
If it can't. Is there any other way?
Thanks
Since you are behind a NAT all your web-servers share the same endpoint. You will need to set up virtual hosts that resolve all requests based on domain information passed in an HTTP packet. The server that hosts these virtual hosts will then parse the incoming packets and distribute the request to the appropriate virtual host based on domain name resolution.
Apache makes this pretty easy through its implementation of name-based virtual hosts.
IIS has a solution as well as this stack overflow answer points to.
Good luck!

Access website over local network from other devices?

I have a website that I'm running locally at localhost:8000. I'd like to access my site from other devices on my network. I've tried to visit the site via my computer's internal IP address via: 127.0.0.1:8000but this doesn't work. Is this possible?
Three most probable things:
Check if there is a network route between the client and the server machine (commands like PING and TRACERT will help);
Check if the server machine has a firewall. If it does, there must be a rule allowing (opening) connections through that port (8000) in TCP;
Most likely, the problem is one of the two above. If not, there's one last thing:
Make sure the web server (the one that serves localhost:8000) is bound to listen to all IP addresses (not only 127.0.0.1).
To know that, search for servername bind all ip addresses on google. E.g., for apache HTTPD, it'd be apache bind all ip addresses.
here is what I do in similar cases:
search rejetto hfs on google, it is single executable less than 1Mb size and download it into your server machine.
after starting it, follow menu->IP addresses. these are all your possible addresess on the server side.
these are your IP addresses to enter, and your port is 8000 as you mentioned.
most possible IP addresses you will find are in the format of following:
192.168.?.?
10.0.0.?
169.254.?.?
besided you will probably need to add a firewall rule for your server app.

Resources