Anyway to find out hosting server LAN IP in nginX? - nginx

When I use $server_addr in my nginX configuration, it returns "127.0.0.1", but my script needs to know the actual LAN IP of the hosting server for some conditional items. Is there anyway to find out actual LAN IP (such as "192.168.1.32") instead of "127.0.0.1" in nginX?

Related

How are 127.0.0.1, 0.0.0.0 and localhost different?

I don't understand the difference between these terms and how they are connected.
I looked at a hosts file on my computer and could see that 127.0.0.1 and localhost are connected but not sure how and I don't know where 0.0.0.0 fits into all this.
I've seen other answers to this question but I'm a newbie and the other answers about loopbacks and meta-addresses weren't easy to follow.
Yes, on your local system localhost does translate into 127.0.0.1, which will always be the IP address of the machine that you are currently using. For example, on your computer accessing 127.0.0.1 (or localhost) will just attempt to open a connection with your own computer (useful if you're hosting a local web server)
Meanwhile, 0.0.0.0 has a different use. On a server or any machine with more than 1 ip address, it can be used to refer to all of the IP addresses that the machine uses. For example, if you create a simple java application with a serverSocket, you may want the server socket to listen for incoming connections on all of the servers IP addresses. You would then set the server socket to listen on 0.0.0.0. Hope this helps!
Any address in the whole 127.0.0.0/8 block will loop sent traffic back inside the computer.
Localhost is normally set to 127.0.0.1, but it could be set on any address in the 127.0.0.0/8 block.
The 0.0.0.0 address really means any IPv4 address.

Port-forwarding and website hosting: Two domains, same ip, different computer

So I have two domains:
http://firstexample.com
http://secondexample.com
on my router I currently have portforwarding so that when someone goes to http://firstexample.com, they see the website that my computer with internal IP 192.168.0.15 is hosting
How can I set it up so that if someone goes to http://secondexample.com, they would see the website that my other computer, with internal ip 192.168.0.16 is hosting?
Both of my computers have the same public IP.
Is it a setting on my router I would change? Or would godaddy allow me to configure something?
No it is not possible to listen for two domains on the same IP/port configuration, using just Layer3/4 functionality alone. Most of the web servers do it based on the Host field in the request. If you are okay with using two ports on your router, that's possible eg. you can do something like following port forwarding
<router_ip>:80 -> 192.168.0.15:80
<router_ip>:8080 -> 192.168.0.16:80
But the problem with that is anyone trying to access http://secondexample.com should always access it as http://secondexample.com:8080 which is very inconvenient.
Here's another alternative you can do -
run a webserver on say 192.168.0.15 like nginx or something and create two backends one for each http://firstexample.com and http://secondexample.com . Refer nginx docs for how to do it. You'd not need three machines for that firstexample.com can run on 192.168.0.15 (except not on a standard port 80 but on a port 8080 say) and secondexample.com would run on another machine. And then add only following entry on your router port forwarding
<router_ip>:80 -> 192.168.0.15:80 # assuming ngninx is listening on port 80.
I am assuming both firstexample.com and secondexample.com do resolve to your router IP address.

How to access a website on VPS with port create?

I try to host my website for learning, on a CentOS free VPS (no support).
I’m allowed to access Apache service via IPv4 by adding a custom port.
Using the format below, I can access the server with my browser.
e.g. 12345 is my custom port that I created for default port 80:
http://xxx.xxx.xxx.xxx:12345
But I cannot access my hosted website http://mywebsite.com (‘the webpage is not available’).
I’ve created the proper DNS record on my DNS provider, and pointed the domain name to the free VPS server IPv6 address (through CloudFlare).
Note: My ISP doesn't provide IPv6 connection and the IP is not ICMP pingable (I can’t create IPv6 tunnel).
Here is my telnet test communication result (not my real IPv6 address):
[root#myserver ~]# telnet mywebsite.com 80
Trying 1a12:1234:1:1::1:1a23...
Connected to mywebsite.com.
Escape character is '^]'.
Connection closed by foreign host.
[root#myserver ~]#
Why I can’t access my website: http://mywebsite.com ?
Okay.., what fixed it was adding on Cloudflare a 'CNAME' record in addition to the existing 'AAAA' record.
Hope this help someone.

Connecting to a ftp server that only allow specific IP address

I need to connect to a FTP server with restricted IP blocking firewall. The problem is my IP is in dynamic. I only need the FTP to work, I'm using Filezilla. My ISP won't allow me to have a static IP that's the big problem. Is there any way i can make this work? Is proxy an alternative?

How Can I Access Locally Hosted IIS WebSite from Remote Computer By My IP Address?

How Can I Access My Locally Hosted IIS WebSite from Remote Computer By My IP Address ?
You have to check you ip here, make sure that you are forwarding port 80 (especially if you're in a locale home network), and then you could access your server by http://<server_ip> e.g. http://192.168.0.6
Note that as long as you don't have a fixed (static) ip, your ip address might change, and you'll have to recheck it.
Another note- The default HTTP port is 80, and by using port 80 you could access your server via browsers without writing the port number. If for any reason you like to switch port, make sure your forward that port number and access your site by http://<server_ip>:<port_number> , e.g. http://192.168.0.6:8080
if you are using some other port. then you can go with http://<ip_address>:<port_no>

Resources