Can a single hosts file entry contain multiple domains/sub-domains? - asp.net

May be this is a weird question, but I am curious to know if single hosts file entry can contain multiple domains on same line?
I know that following is okay for host entry:
127.0.0.1 somedomain.com
But, I want to know if following would work:
127.0.0.1 somedomain.com, alternate-domain.com, subdomain.domain.com
or
127.0.0.1 somedomain.com, *.domain.com
(Note: I am doing hosts file entries on windows)
May be this has been asked before, but I googled before writing my question, and I didn't quite find a good answer. Thanks for taking time to read and answering, it will be pretty helpful.

I found the solution.
On IIS, I had to add https in bindings associating it to use IIS Development Certificate for SSL in my development environment.
Also, in the process I found that both of the following wiil work for me.
127.0.0.1 somedomain.com, alternate-domain.com, subdomain.domain.com
or
127.0.0.1 somedomain.com alternate-domain.com subdomain.domain.com
Spaces and commas both work, and I can add multiple domains, subdomains combinations on same line.
Also, if you are moving from a non-secure domain to secure domain/subdomain, SSL certificate needs to be setup on web server for it, else it would end up showing an error in the browser.
Cheers!

Related

VestaCP - All domains point to the same website. Why?

I have a bit of a problem. I setup several new domains on VestaCP, but they all point to the same default website. Part of the problem I guess is that all DNS records point to the same IP, but Vesta doesn't seem to know which website to take you to, so it takes you to a default website.
However, this problem only happens with HTTP, HTTPS forwards to the correct website. I don't know why. Is there a .conf somewhere that needs to be edited, or am I doing something wrong in VestaCP?
My setup is running on Digital Ocean -- Ubuntu 18.04, Nginx + php-fpm
Your help appreciated.
Chceck if all DNS goes to IP of server with VestaCP. If yes, try look into /home/yourloginname/web Is there every your website? If yes, try to look to aliases. If you have subdomains, maybe head domain have alias *.domain.com .
And if your answer was no for some of questions above, try look into /etc/bind/named.conf where should have every domain 1 row for example:
zone "domain.eu" {type master; file "/home/admin/conf/dns/domain.eu.db";};
If not, add this one. Hope will be helpful.

MAMP could not lookup up localhost. Website unavailable

A weird error appeared that all of a sudden http://localhost:8888/... is not available. A day ago it worked perfectly fine and now I get this error although I have not installed any software, nor updated MAMP nor updated my Operating System. I have been researching all day of what could be the problem and found several answers which solved other people's problem but sadly not mine. The question is: How can I get my localhost working again?
Once I enter the IP (http://127.0.0.1:8888) the website loads, however, all my links use http://localhost:8888, which means I would have to change all the links to use the IP. There are scripts that do so, but I really want to understand the background and find the root of this problem. I have tried several things:
Changing the Apache ports to another number which can be done under MAMP Preferences. I get the same error no matter which port I change it to.
Editing my etc/hosts file in order to link 127.0.0.1 to localhost, which I really did not have to do since the code was already there. After I have done this, I opened my terminal and entered sudo killall -HUP mDNSResponder in order to flush the DNS Cache. Afterwards, I restarted my computer and annoyingly the error keeps appearing. Somehow, localhost is not linked to 127.0.0.1, which I think is comparable to when the domain name of a website is not connected to the server IP which can be configured with the Nameservers. This brings me to my third point and last point.
I looked deeper into the location and opened the "httpd.conf" file found under the path "etc/apache2/httpd.conf" where I can configure the Apache HTTP Server. I searched for any ServerName and the only code that appears is some comments describing it. This includes #ServerName www.example.com:80 and a short description before. I've tried adding a new ServerName as ServerName localhost:8888 and even simply ServerName localhost, still nothing happens.
I've tried other obvious things which are not worthy mentioning for. This seems to me either something really complex to which my knowledge does not reach or something very silly I missed out.
For the record, the etc/hosts file contains some weird addresses:
##\n# Host Database\n#\n# localhost is used to configure the loopback interface\n# when the system is booting. Do not change this entry.\n##\n127.0.0.1 localhost\n255.255.255.255 broadcasthost\n::1 localhost \nfe80::1%lo0 localhost\n\n##SYS##\n127.0.0.1 inst.shoppingate.info\n127.0.0.1 service.shoppingate.info\n127.0.0.1 indexx.org\n127.0.0.1 f.flshbsjs.info\n127.0.0.1 gsy.testersgroupfun.com\n127.0.0.1 sendmessagebox.com\n127.0.0.1 t1.inskinad.com\n127.0.0.1 q.crbfmcjs.info\n127.0.0.1 static.donation-tools.org\n127.0.0.1 istatic.datafastguru.info\n127.0.0.1 static.boostsaves.com\n127.0.0.1 www.best-deals-products.com\n127.0.0.1 fge.solartrendinc.com\n127.0.0.1 nps.pastaleads.com\n127.0.0.1 digitaloptout.com\n127.0.0.1 cdncache-a.akamaihd.net\n127.0.0.1 cdncache1-a.akamaihd.net\n127.0.0.1 rvzr-a.akamaihd.net\n127.0.0.1 rvzr2-a.akamaihd.net\n127.0.0.1 asrv-a.akamaihd.net\n127.0.0.1 cdn.visadd.com\n127.0.0.1 a.visadd.com\n127.0.0.1 ydt.winsurfingclub.com\n127.0.0.1 client.foxydeal.com\n127.0.0.1 s.hklmm.com\n127.0.0.1 i.crbsjs.info\n127.0.0.1 wwm.determineyourroad.com\n127.0.0.1 ext1.engageya.com\n127.0.0.1 ext2.engageya.com\n127.0.0.1 a.tfxiq.com\n127.0.0.1 cdn.staticwebdom.com\n127.0.0.1 api.jollywallet.com\n127.0.0.1 i_crbsjs_info.tlscdn.com\n127.0.0.1 i_flshbsjs_info.tlscdn.com\n127.0.0.1 ppj.qwikbookprint.com\n127.0.0.1 homedesigntreasure.com\n127.0.0.1 www.superfish.com\n127.0.0.1 istatic.eshopcomp.com\n64.251.22.253 shmactustus.com\n64.251.22.253 www.google-analytics.com\n##SYS##
I also tried deleting all the remaining addresses leaving only:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
But, after I restart my computer, all the old addresses I previously deleted appear again and the error is still the same. The thing is, this happened all of a sudden overnight and I did not expect this to occur. Does anybody know what is going on? I am open to any suggestions and appreciate your help. Best Regards!!

Nginx two virtual hosts on with domain name one in localhost

On my Nginx I've got two hosts.
One with the values
server_name = www.mydomain.com;
root /var/www/production/myFirstWebSite;
and the other with
server_name=localhost;
root /var/www/development/mySecondWebSite;
To my domain registrar account I configured the DNS with two A record "
www IN A myIP
IN A myIP
This is cool, i can reach my first website with www.mydomain.com or mydomain.com.
Now the problem is how to reach my second website which is in development and I don't buy the domain name. And myIP/development/myScondWebSite is no more working ...
I think that the problem come from the DNS entries but I'm not sure.
Do you've got some ideas ?
Thanks in advance.
There's a couple of ways I could think of to access the localhost one.
Creating a subdomain instead of localhost
This is the best one I'd recommend, try doing something like server_name localhost.mydomain.com.
If you need to put further security, you could make it only allow a certain IP(s) or a range of IPs.
Play with your hosts file
In this specific case I would not recommend this, because you're messing with localhost it self, might break some other stuff on your machine, if it was any other name I could have said it's fine.
Use an ssh tunnel to the server
In this method you create a dynamic port on your ssh connection and set your browser to pass all traffic through tunnel which goes to the server then it's handled from there, so if you run localhost for example it would be like running localhost from over there, but since this involved a browser setting, you need to remember to disable it after you disconnect the ssh connection otherwise the browser would return an error saying that the proxy server is refusing the connection.
Using a local Nginx as a proxy
This one I just came up with right now, and I can't say If it would work or not, the 3 before I've worked with before and I know they work.
You'd set a certain domain name that your local nginx would capture and then proxy it to the remote server, but edit the host header setting it to localhost instead, that way it would match the localhost in the remote machine, if this one works it would not need any setting to be turned on and off every time.
Out of all these, I'd recommend the first one first (if it's an option), then try the last one if you don't want to keep turning things on and off before and after each setting.

Add subdomain to localhost URL

I am writing an web application that behaves differently depending on a url prefix. The format is something like:
https://myprefix.mycompany.com
The web app behaves differently based on myprefix. My web app extract that part from the URL and act on that.
However, when I test on my local, I use an localhost address:
https://localhost:1234
I counldn't do something like:
https://myprefix.localhost:1234
What is the best way for me to test this scenario?
Many thanks
Unfortunately, because localhost is not a proper domain, you can't add a subdomain to it like that. You can, however, trick your computer into thinking it owns a specific domain and test things that way. For instance, if you have a UNIX-based operating system, open (as root) the file /etc/hosts and add a line (or lines) like this:
127.0.0.1 example.com
127.0.0.1 subdomain.example.com
Your computer will now treat both example.com and subdomain.example.com as belonging to itself. If you visit either in your web browser, they will work the same, in principle, as localhost, but your web server will see the correct domain in its Host header.
I'm not sure about same behaviour on windows. I'm working on linux mint.
You can use lvh.me:port as a local domain. You can imagine that your project is deployed on localhost:port on this domain.
Instead of sub.localhost:port you've to use sub.lvh.me:port
UPDATE
sub.localhost:port works on Chrome.
Note: Firefox automatically adds www. at the beginning of entered domain that can cause problems with subdomains testing
For Windows users, based on this answer and per this comment, you can achieve this by adding ports to localhost via the hosts file that resides at this path:
C:\Windows\System32\drivers\etc\hosts
And append lines like the following to it:
127.0.0.1 example.com
127.0.0.1 subdomain.example.com
One-Line Solution for Windows
Open PowerShell as Administrator and run the following command, replacing sub.mydomain.com with whatever you want.
"`n127.0.0.1 sub.mydomain.com" | Out-File C:\Windows\System32\drivers\etc\hosts -encoding ASCII -append
Breakdown:
`n - newline
127.0.0.1 - loopback address
sub.mydomain.com - domain name
| Out-File C:\Windows\System32\drivers\etc\hosts - pipe the string to the hosts
-encoding ASCII - correct encoding
-append - append to end of file (important!)
You should be using the .test domain for things like that. That is what .test is for. localhost is not supposed to have any subdomains.
To do so violates the approved RFC standards. localhost has an A record and in IPv6 environments, an AAAA record. All other DNS record types, including SOA are forbidden.
Without an SOA record, it cannot be a zone apex that has sub-records, so no subdomains nor delegations are permitted. Even the recent RFC draft titled Let localhost be localhost is consistent with this.
https://myprefix.mycompany.localhost:1234
This should do the trick. Because localhost is a top-level-domain, it behaves like a .com in production code.
It took me a bit of time to find public wildcard DNS domains pointing to localhost so I'm leaving it here for future reference.
The domain that worked for me is localtest.me. That domain and its sub-domains resolve to 127.0.0.1 and ::1.
For example:
$ host localtest.me
localtest.me has address 127.0.0.1
localtest.me has IPv6 address ::1
$ host some-sub-domain.localtest.me
some-sub-domain.localtest.me has address 127.0.0.1
some-sub-domain.localtest.me has IPv6 address ::1
A maintained list of other public wildcard DNS domains that point to localhost can be found in this Gist.
From WSL in Windows:
First navigate to /mnt/c/Windows/System32/drivers/etc(Navigate cause, you may find more interesting files. Don't play here, but see what do they do)
Then do nano hosts(add at very bottom)
127.0.0.1 random.com
127.0.0.1 auth.random.com

How do I give access to another computer on my network, to my website hosted locally?

We have a local instance of IIS 7 running with a website. Instead of the default "localhost" we have something like, mysite.compname.com. This is a separate entry into IIS 7 and the default website was removed to prevent confusion.
Then in our host file we an entry like this:
127.0.0.1 mysite.compname.com
Now when I try to hit this url, http://127.0.0.1/ApplicationName/Project/AddProject.aspx technically it should work, but instead I get a 404. I can vouch that this isn't a problem with the application, because if I navigate to http://mysite.compname.com/ApplicationName/Project/AddProject.aspx it works fine.
My end goal is to be able to give someone my computer name, so that they can visit a test page, so the url above I think would get turned into this http://computername/ApplicationName/Project/AddProject.aspx. Any help or at least links to understanding would help because I'm not sure where my issue is coming from.
It sounds like the IIS site / application is configured using a Host Header.
This means that the site will only respond if the host header sent by the browser matches the one configured for the site.
This is a standard method to allow one server to host sites for many host and domain names.
If you wish to allow others to view the site on your computer you will need to either have a local DNS server which you can edit, or, probably the easiest option, get them to edit their host files to include
<your IP> mysite.compname.com.
Remember to open the requisite ports (probably only 80, maybe 443 for https) in your firewall.
Or, you can try to edit the site config to remove or modify the Host Header requirement. See the first link for details, but be careful, it's easy to break things if you don't know the entire architecture of the site.

Resources