Multiple localhost:80-bound sites in IIS? - iis

(You can skip directly to the question, but the context is on the background section.)
Technical Context
Windows 8
IIS 7
Background:
As several others, I work with IIS and from time to time I need to set up a local version of a site. Now, in setting up different sites, it is quite common to just assign them different ports so that they don't overlap. So you could have your site A at port 80, your site B at port 81 and so on.
Now, I want to setup the bindings so that I am able to have several sites under port 80 and with the header host distinction I can at the same time give meaningful URLs to these sites.
An option to do this is with adding entries to your hosts file, such as:
127.0.0.1 siteA.com
127.0.0.1 siteB.com
And with this, you should be able to browse to siteA.com or siteB.com and have that working locally.
But I want to take one more step, as localhost is already set up to match 127.0.0.1, so:
Question:
I had set up the IIS bindings as:
site host header port
siteA siteA.localhost 80
siteB siteB.localhost 80
And I expected that I would be able to browse to http://siteA.localhost/ and http://siteB.localhost/ and get my sites.
However, when I browse, it seems that my requests never reach IIS, and the address is not resolved.
Why isn't that working?
Update:
I have chosen chue x's answer because he explained why this doesn't work. For those that may follow my same path, you may think "well, I could just add *.localhost in the hosts file and it should be done." or even switch to *.local or *.localdev.com or something of that sort.
That, however, doesn't work: Wildcards in a Windows hosts file
As chue x pointed out, our only approach right now is to keep adding entries to the hosts file or, how they explain in the linked question, to use another DNS server.

Your hosts file needs to match your IIS bindings, which have to match the url browser.
So if your hosts file looks like:
127.0.0.1 siteA.localhost
127.0.0.1 siteB.localhost
Your IIS bindings need to be:
site host header port
siteA siteA.localhost 80
siteB siteB.localhost 80
Finally, from the local machine, you need to browse to:
http://siteA.localhost
EDIT - If you are trying to do the above without adding the hosts entries for siteA and siteB, it won't work. DNS won't find it. So for example, what happens if you try to browse to "foo.stackoverflow.com" - the request will fail even though "stackoverflow.com" is a known address.

Related

Create 3 sites under DefaultWebSite with https access having different port number

I have 3 sites(virtual directories) registered under the Default Web Site in IIS, those can access like below:
http://localhost/Site1
http://localhost/Site2
http://localhost/Site3
Currently I have one port number which is port 80.
I need to setup those sites with https having different port numbers, like below:
https://demo.mydomain.com:5001/Site1
https://demo.mydomain.com:5002/Site2
https://demo.mydomain.com:5003/Site3
I am new to the IIS. Can someone please help me out with the approach to solve the above scenario?
is the domain already pointing to your webserver or are you trying to achieve this on you development machine?
If the domain is already pointing to the server, you can do this IIS by adding bindings to your websites (in your case its the defaultwebsite).
You can achieve this by right-clicking the website. Here you can see "Edit Bindings". You will have to add a binding foreach port. Just click on "add" and type in the right hostname (demo.mydomain.com) and the port. You can also choose a certificate here for the https connection.
If you are trying to achieve this on your dev machine, you will also have to add your hostname to the windows hosts-file. Under "C:\Windows\System32\drivers\etc\hosts" add the line "127.0.0.1 demo.mydomain.com".
Jonathan

Redirect TLD (dev) to local IIS

In the office, we have already setup a redirect in the DNS to push .dev back to the localhost. The issue is when I am not in the office this does not work. I edited my host file for the websites but as I add more in the future I would prefer to not have to edit my host file.
Is there a way, within my computer, that I can force the TLD of .dev to always go back to my localhost?
I realize I may have to find a way to do this on my router so that the DNS is resolved.
Example:
- Local IIS
-- Website A (with a Host Name Binding of website-a.dev)
-- Website B (with a Host Name Binding of website-b.dev)
When I open a browser on my local box and type in website-a.dev, it should loop back to my local IIS and pull this website. Same thing for website-b.dev, of course, going to the other website. Now I know if at work we have setup the DNS to allow for this but I want to know if this can be done at home, where I do not have direct access to the DNS.
I know I can just put into my host file
127.0.0.1 website-a.dev
But I want a catch all for .Dev to go back to 127.0.0.1
Take a look at:
https://superuser.com/questions/135595/using-wildcards-in-names-in-windows-hosts-file
It explains that using Acrylic allows you to use wildcards and acts just like your host file.

.net localhost url to server as redirect for hosts file entry

I want to use something like http://localhost:6240 as entry in win hosts file.
For example when developing locally, I want when I'll open this domain dev.mysite.com the browser to navigate to http://localhost:6240
The Windows or any hosts file doesn't know anything about ports. There is no way to redirect traffic on that level.
Don't use ports, add dev.mysite.com to your hosts file and also as a host-header binding to the IIS site you want use.
You could also try to add URL-rewrite-rules and redirect request to a different site, but that is much more complicated.

Linux apache /etc/hosts setup on a live server

I have a Linode server operating under a single IP Address. I access various websites via the single IP addresses in the following format: http://x.x.x.x/mysite1
Is it possible to access my individual websites, mysite1 etc, via names set in /etc/hosts?
In /etc/hosts I tried setting:
x.x.x.x dev.mysite
But, attempting to access my website via http://dev.mysite results in a webpage not found error.
Is what I'm trying to accomplish possible?
As long as you have made the /etc/hosts modification on the machine that is trying to access the website, then yes this is possible. Although you will also have to modify your Apache config so it knows which website to display when "dev.mysite" is requested. My Apache knowledge is rudimentary but I believe you want VirtualHost for this.
If you want other people to access the website without modifying their hosts file, you will need to buy a domain. For instance, if you buy xyz.com, you can put your sites under site1.xyz.com, site2.xyz.com and so on.
I believe Your /etc/hosts needs no change . dev.mysite already points to mysite.com which has an entry in /etc/hosts
You need to modify your web server (nginx / Apache)listening in port 80 to accept requests on dev.mysite

How to host multiple iis websites cleanly mapped to different ports?

I'm having trouble finding info on this one, even having access to my company domain controller I still can't see what configuration is causing the same behavior I want to mimic on my home server.
I'm working from a test environment on my home PC and would like the following behavior. Note that I do not require any of these sites be accessible anywhere but my local machine, again, I just want to learn.
My Goal:
To configure IIS to host multiple sites, accessible via "aliases" which map to different ports. For example:
home -> localhost:81
test -> localhost:82
dev -> localhost:83
Furthermore, I want the url in my address bar to actually BE what it says on the left, not simply redirect, BLEH! So if I type "home/" in my address bar, it should load the page at "http://home/".
How can I achieve this? Thanks... ;)
Here's what I have configured in my bindings for the site so far, but no cigar...
first you need to edit your hosts file (probably C:\WINDOWS\System32\drivers\etc) so that you resolve home for example to localhost, add records like this:
127.0.0.1 home
127.0.0.1 test
...
Then you should be able to set up your IIS site with the Host name as home, but leave the port to the default of 80.
When I create a site in IIS I select for IP "All Unassigned" and then make a unique port.
I access my sites via the outside world like this:
http://mbdev.myftp.biz:8004
http://mbdev.myftp.biz:8006
Those all go to demos sites.

Resources