Access virtual host without domain pointing to it - redirect

I have a domain which pointed to an IP address (A). This IP address hosts several other websites with their domains. I now forwarded this domain to another host but I also need to access the old site which now does not have a domain pointing to it. Of course I can't just access the old site by typing the IP address into the browser. How can I do it instead?

If you're on unix, you should modify the /etc/hosts file; C:\Windows\System32\Drivers\etc\hosts if you're on Windows. (This will likely require admin privileges.)
This overrides the public DNS which would otherwise map an IP to a domain name. The change tells your machine that the old IP address is the location of example.com, where your hosts file has a line that reads:
xxx.xx.xx.xx example.com www.example.com
And xxx.xx.xx.xx is your old server's IP.
Remember to comment out or remove the line when you're done! You may confuse your future self, otherwise!

"Host" Header in HTTP is used to identify which of the many websites to visit on a virtual hosting web server. Virtual hosting is when a single IP address hosts websites(http content) for many different domains.
For eg. "Host: www.example.com"
You will find such a header in all virtual hosting websites.
Use an extension like Tamper chrome to add Host to the header. Specify your domain name in this header.
Illustration -
The university in which I studied uses virtual hosting, hence using Host header is imperative.
See the following image.
Now, if I type the IP address (obtained from ping utility) directly. You see a default page.
Now If I use tamper chrome extension to add Host header.
We can see that it lands on a page on bvcoend.ac.in domain.
I have to polish it further so that the landing page is the home page, but this process captures the essence of Host header used in virtual hosting.
Update : Using Fiddler to modify Host header seems to work fine for me, somehow tamper chrome isn't doing it's job perfectly (miss the good old Firefox Tamper data days).

Related

How do you Configure Stapi CMS to Use Custom Domain Name

The default port for strapi is 1337, and default hostname is "Localhost".
I changed the hostname in the server.json file (that's inside the development folder) to "example.com" and saved that change.
However, when I start the program (by typing npm start in the terminal) although the output indicates that strapi is indeed hosting on "example.org" (and says the administration is at "example.org/admin"), upon navigating to example.org:1337, in a web browser, the page is not accessible. Yet, it is accessible when I navigate to localhost:1337.
I'm new to strapi. Any help will be appreciated. Thanks in advance!
Changing the domain name, inside of a server.json configuration file, won't likely result in your web browser being able to resolve that domain.
When your web browser tries to discover the IP address of a domain name, it first looks in your operating system's host file. If it cannot find the ip address of the domain there, it then tries to look for it at the DNS server that provides name-lookup for your local network.
DNS will typically point your domain to the public IP address of your web server and sometimes, if your web server is located on the same LAN you are, it can be tricky to teach the firewall or local DNS server how to route your browser's request within your LAN.
If you do edit your host file, to make the domain point to an internal IP address, you'll want to remove that entry later in order to access the domain when you are not on your LAN.

Adding subdomain pointing to same IP but different port

I have a domain name registered at ovh.com, let's say it's called domain.com.
This domain is pointing on my router's public IP, then I redirect the https port 443 of my router to my server port 443. So when we go to domain.com it redirects to my server:443.
To be more accurate, domain.com just redirect to my router's public IP. So for example if I use a graphic database manager, I can tell him that the server address is domain.com:[SGBD port] and It will works.
But all my applications are running on this same server. And to add a little more security, I am not using the usual port for all protocols. So let's say my port are the following :
git : 50000
SGBD : 55000
cloud : 60000
website 65000
and some others, for example some TCP ports between 40000 and 50000.
My git and my cloud have a graphical manager I can access by typing domain.com:50000 or domain.com:60000 in my web browser from everywhere. I use the same URL on all my software. domain.com:50000 for my git client, domain.com:55000 for my database client and so on.
This way is working perfectly but there are 2 problems annoying me :
The first one is that I have to tell the port number to everyone who's susceptible to use my applications. But like I said I am not using usual port number for a little more security so I don't want to share these numbers with everyone.
The second problem is more important :
When I am somewhere, for example at work, it's possible that the firewall is blocking the port numbers I am using. So my personal git isn't accessible, same for my cloud etc.
To solve these problem in one move I wanted to add subdomain on my domain and redirect these subdomain to my differents ports. For example :
website : domain.com:65000
git.domain.com ==> domain.com:50000
SGBD.domain.com ==> domain.com:55000
cloud.domain.com ==> domain.com:60000
So in my mind, with this solution I can type git.domain.com in my browser to initiate the communication by https (the https port is almost never blocked), then redirect it to my router's port 50000 from OVH then my router redirect it to the git port of my server.
But obviously this would be to good to be truth.
When creating a subdomain (at least on OVH ?) we can't specify a port. So I can't set git.domain.com is redirecting to myRouterIp:50000 but just to myRouterIp. So with a web browser, typing git.domain.com will redirect to myRouterIp:443, which is already taken by my website.
So i'm a little confused. Do I have to buy one router with a different public IP per application then making all differents subdomain pointing on a different router ? I almost sure it's a bit ridiculous. How do you think I can solve it ?
As you correctly noticed, in your DNS console you can't specify port; the reason is that DNS does not care about ports, its only purpose is to resolve hostnames to IP addresses.
Another thing important for your problem is that most (non http) application clients will, even if they use friendly hostname, resolve that name to IP address before initiating the connection to your router/server, and then use that IP address for communicating to router/server. That means that when request reaches a port on your router/server, there will be no way for router/server to determine which hostname was initially used.
The rare exception to this is HTTP, where the browser is always sending the requested hostname in Host HTTP header. That means that you can run multiple different websites on one IP address on the same port (that is how shared web hosting works, for example). Setting this up should be pretty straightforward, but is probably out of scope on SO, try SF or SU.
For other (non HTTP services), the only solution is to run them on different ports (which you already do), or to have multiple public IP addresses (which might be difficult to get from your ISP). Also, running non-http services on some random non-default ports (and telling that port number to your users) might be (very sightly) more secure than running them on their respective default ports.
Depending on your use case, one other possible solution would be to have your users connect to your local network using secure VPN, and after that they could have access to your services (which would run on different private IP addresses and any port you like).

Redirect/rewrite to different internal IIS sites using query string

EDIT: Ugh I forgot to put this on Server Fault...
I have an Azure VM that is hosting a web application.
The application will be accessible via the VM's IP address:
http://191.238.112.62
I want to be able to use query strings to redirect to completely different sites that are within the local IIS. For example:
http://191.238.112.62/?site=1
would redirect to
www.site1.com
The way I have structured IIS can be seen below:
Each site has an entry in the systems host file.
127.0.0.1 wwww.site1.com
127.0.0.1 wwww.site2.com
127.0.0.1 wwww.site3.com
There is likely a better way to achieve what I am going for here so any pointers would be greatly appreciated.
Thanks.
Here is how I would do it. Not sure why you want to use query strings for this as IIS is made to do that if you configure it properly.
In your DNS server register all your websites to point to that IP. This is for when you go live. For development the hosts file is a good solution.
When you create the websites add a Host header like below
Now try loading any website by their full name
http://www.site1.com
http://www.site2.com
http://www.site3.com
Here is more info about IIS host headers.
Again, when you go live make sure you have the DNS set up for all the websites to point to the IP address of your server.
Hope this helps.
Edit based on comment:
Right, here is how I solved this in the past.
You can do all this with the hosts file but it's less painful if you have a proper DNS server to resolve the names.
The basic idea is to use slightly different URLs for development on the local machine.
All devs would have site1.com point to the IP of the shared server and site1.com.local point to 127.0.0.1. So a hosts file on a developer machine would look something like:
191.238.112.62 www.site1.com
127.0.0.1 www.site1.com.local
On all development machines you need to make sure you have the .local host header for all sites.
On the shared server you just need to add the right host headers and no hosts file changes. It's actually a bad idea to change the server hosts file.

Access local site with subdomain on iPhone

I understand that you can access your computer's local site from a mobile device running on the same network by entering your computer's IP address (with relevant local port) into the address bar. However, I often use subdomains for development. On my local I access subdomains using lvh.me. For example:
blog.lvh.me
However, this will not work for mobile because lvh.me is redirecting to the IP 127.0.0.1 .
Is there a way to access a subdomain on an IP address? Essentially, doing the same thing as the above code but allowing for a dynamic IP address depending on the IP my computer has at the time?
So, after continuing research, I found an awesome tool that allows for exactly the above functionality:
xip.io
For example, if my computer has the IP address of 124.4.1.3 and I was running a web server at blog.lvh.me, where lvh.me redirects to localhost or 127.0.0.1, I could access my computer's localhost from another device on the network using blog.124.4.1.3.xip.io
I hope that helps someone!
Sidenote: The app in question was running on a rails server and the above setup required the following setting to be added to the environments/development.rb file:
config.action_dispatch.tld_length = 5
As rails was running on port 3000, this also required a url like:
blog.124.4.1.3.xip.io:3000

Facebook Apps: Allowing a single Facebook App to run on arbitrary private network address

I have a development server (Java servlet container) running on my computer inside my private network (IP range 192.168.0.0 to 192.168.255.255). This development server executes my integration testing environment. This testing environment has its own Facebook App ID. Having the server run in the 192.168.x.y range allows my colleagues to test the website, login to my local website with their Facebook accounts etc..
At https://developers.facebook.com -> in the Facebook Apps settings -> located under "Basic settings" -> in the "Website with Facebook Login" field, I have set http://192.168.2.106:8080, as this is the address-port combination that my development server binds to.
Due to DHCP, my computer now has a slightly different IP address, namely 192.168.2.109. Whenever I start up my server and then try to do anything Facebook-API related (e.g. Facebook Login), I get the following error message from Facebook
{
"error": {
"message": "Invalid redirect_uri: Given URL is not allowed by the Application configuration.",
"type": "OAuthException",
"code": 191
}
}
Is there a way to have a Facebook App allow a "range of IP address websites with Facebook Login"? What other solutions can you suggest?
My colleagues shall be able to also start up the development server on their own machines, with their own private network addresses. Therefore, the same Facebook App ID shall work on different machines with different IP addresses and still be accessible to everybody inside the private network.
Notice that setting "Website with Facebook Login" to localhost makes the development server only available to the same machine it is running on. This unfortunately prevents colleagues from accessing this development server instance.
Update
Filed bug: https://developers.facebook.com/bugs/606277079382609
If you could get away of using localhost, then there is a very simple way:
Make the facebook app redirect to http://lvh.me:3000/ (or whatever port your server is listening on localhost). A benevolent developer owns the lvh.me domain and had the DNS setup to point to localhost. I've tried this and that's what I used for development testing.
Similarly, you could do stuff like that and points a DNS record of a domain you own to a range of local ip. I am not familiar with DNS so I am not sure how to set it up or if it's possible.
If you're running on Windows you could try changing your hosts file in C:\Windows\System32\drivers\etc
and add your IP to an imaginary domain (your colleagues should do it too) and put that domain in Facebook Settings panel.
I'm not sure about this so tell me if it works :)
As far as i know you cannot setup an IP range in your application setting, the redirect_uri is typically meant to handle urls with domain names, which is usually the case with with public websites.
The best way to avoid this problem is to make sure you local development server has always gets the same IP, which is generally a good practice if you are writing a server.
there are several ways to do it depending on the network setup, here are two option:
Setup your DHCP server to always assign the same IP to your dev server MAC address
Bend the rules a little bit and setup your computer to claim an unused IP address. DHCP servers typically assign IPs in order (will start from 192.168.1.1 and work up to 192.168.254.254) so have your computer claim an IP in the higher part of the range (Ping the IP first to make sure it's not being used)
Instead of using an IP address, use localhost.
So hxxp://192.168.1.20 would become hxxp://localhost
(replace xx with tt)
This resolves back to the local machine, whatever its IP address is. I am assuming that your development server is running on your PC, using WAMP or something similar. I draw this assumption because you state that it must run on any laptop in any network environment.
If you own a domain you could create a subdomain test.mydomain.com pointing to 192.168.2.109.
When your address should change again, you can change the entry accordingly.
There is no reason why a DNS entry could not point to a IP address from the 192.168 range. For someone outside your network it will not be of much use, because he can't access your IP address from the outside, but for your co-workers within the network it will work.
If a coworker wants to run the web app on his own PC, he can of course override this setting using his own hosts file.