How can I access a website configured with host headers in IIS on the local machine? - iis

When using host headers to host multiple websites on the same IP address in IIS, is there any way of accessing that website from a browser running on the local machine?
This is normally required when a given web component only allows configuration from the local machine. It's also useful when things like ASP.Net's built in error handling isn't working and you can only view the error in the browser but don't want to allow remote users to see it.
This has baffled me for a while and everytime I come across it I end up giving up in frustration and reconfigure stuff so I can accomplish such tasks remotely.
Added: #Ishmaeel - modifying hosts doesn't seem to help - you either get a 400 error (if all websites have host headers) or whichever site is configured without a host header.

Just an idea: Mapping the hostname to 127.0.0.1 in the hosts ($WINDOWS$\system32\drivers\etc) file may help. This way you should be able to pull up the local IIS site by typing the hostname as if it's a remote server

Maybe I am not understanding the question, but what's wrong with just typing in the URL for the website? If it's the matter of domain name resolution, you can point to the right DNS or put it in hosts file.

eed3si9n -- if you are trying to access a url locally and you use host headers you cant just type in the url: for example you have 2 websites (website1.com website2.com) on 1 server using host headers. the local ip of the web server is 192.168.1.50 --> if you type in 192.168.1.50 you will get a 'page cannot found'. if you put in the url website1.com or website2.com you will be accessing the sites from the outside (not locally).
so the problem is how to access the sites locally not from the outside -- for example i need this ability so that i can access locally as the test sites are only available locally. not from the outside...

You can try telnetting to the server.
$ telnet localhost 80
(type these lines manually)
GET / HTTP/1.1
Host: www.example.com
(exchange www.example.com for the host name your server is mapped to)

I would assume the only way you can do this is assigning a custom port to the specific website you want to monitor and just access it as "localhost:CustomPort".

Related

Is it possible to bind a domain to another domain instead of a server ip?

How to bypass/manipulate HTTP_HOST?
I want, in a browser, that when I go to blabla.com, it actually opens example.com(ip:123.45.56.78).
Using windows .hosts file, I can bind blabla.com to 123.45.56.78 server, and manipulate it.
This works with dedicated ip websites, but on shared servers there are several websites binded with IP (if blabla.com is not set on that ip already) then it shows "FORBIDDEN, domain doesn't exist on server".
Is there any way that visiting blabla.com opened example.com?
The reason it doesn't work is the hosts file does not affect the HTTP host header sent by the browser.
It is possible to do that though if you use e.g. Burp Suite as an HTTP proxy.
Proxy > Options > Match and Replace allows the host header to be rewritten.
Options > Hostname Resolution allows the domain to be rebinded.

Node.js Proxy for out going calls

I am trying to create a local mockup server for an iOS app. I have a running deployed server like url: "http://some-running-server.com/" I would like to be able to use a local http://127.0.0.1/getuser using node.js.
In the app i would user http://some-running-server.com/getuser
I have seen "Charles" application can do this. Maybe someone have done this in Nodes, so you a able to test agents a local mockup using only node.js?
Thanks
Regards
Setup your browser to use 127.0.0.1 as a proxy (network settings), then run your code on localhost (127.0.0.1) and respond to the request. The url can stay the same as the original one. You can use node-http-proxy to forward the request to the original server, if you want to.
You can add the url to your hosts file. If your on OSX or Linux you can find it in etc/hosts. On windows the file is at %systemroot%\system32\drivers\etc\ just map the url to your local IP
127.0.0.1 localhost
# mapping some-running-server to localhost for development
127.0.0.1 http://some-running-server.com
Just remember to remove the entry when you go to production!

IIS 7.5 difference when querying css item from localhost and externally

After 4 hours of looking through stack overflow and searching Google I've finally decided to go check in with the "hopefully" gurus...
My problem is this, when querying from the local machine through remote desktop, querying for www.domainname.com/Content/Styles/reset.css i get the css fine.
When doing the same from an external machine, I get a 404 error... I know why, the reason is that it's trying to get the file from:
C:\inetpub\wwwroot\Content\Styles\reset.css
This is kind of bad considering that the website is actually hosted at: c:\http\www.domainname.com\
The error in the browser, from IIS, gives the following information:
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://www.domainname.com:80/Content/Styles/reset.css
Physical Path C:\inetpub\wwwroot\Content\Styles\reset.css
Logon Method Anonymous
Logon User Anonymous
I've been looking at the other sites running on the IIS, and none of them point to InetPub as their directory, so I simply can't see why it's trying to get the item from this path.
Calling the main application, a MVC based site running Umbraco, works fine, or rather, all the dynamic content works fine, just not static content.
To give a little more information:
Currently the IIS 7.5 has 4 sites and 1 ftp server running.
1 site with the following bindings:
http - this 1st site host name - port 80 - ip address *
https - blank host name - port 443 - ip address *
1 site with the following bindings:
http - the 2nd site host name - port 80 - ip address *
1 domain with the following bindings:
http - the 3rd site host name - port 80 - ip address *
The actual domain
http - www.domainname.com - port 80 - ip address *
And finally a ftp server
I hope that someone have any idea what is going on...
Best regards and praying (despite being an atheist),
Poul
Could it be that the Static File Handler is not included for your website?
Check for your website if the Handler Mappings contains Static File as Handler. ( preferrably at the bottom of the list)
Update:
Is there a physical folder under wwwroot called content\styles? or a folder www.domainname.com for that matter?
Did you look at logs from IIS for the application pool of this website
--> C:\inetpub\logs\LogFiles\W3SVCxx (xx = number assigned to your app pool) I forgot how to find that on ( usually I quickly check the couple of folders here.
Maybe it's a security problem -> do you see events in the security eventlogger.
So I found the problem...
It turns out to be a Proxy issue... As this is a new site, the DNS wasn't set up yet and we were using the HOSTS file.
Unfortunately in Bangkok when using a Cable connection, True (the largest ISP) forces you to use a Proxy, without telling you...
Now the DNS was actually pointing to another IIS server...
When I made my request, asking for a file on domain name X.. My machine looked up the IP address through my HOSTS file, sent the request, the proxy then also did a DNS lookup, but got another IP address, and forwarded the request to this IP address instead.
The IIS on that server, knew the IP, knew the domain name, but had another configuration and didn't know the file we were asking for (for the new website)...
So indeed there is a logical explanation for everything, just not always an obvious one.
I actually got onto the problem by testing with another domain, one that didn't exist at all, on this one the proxy of course could not look it up, and started returning code 324.

Will changing HOSTS file to block unwanted sites mess up IIS?

I've got IIS set up on 127.0.0.l and I'm tinkering with adware blockers that use 127.0.0.1 as the address to route malicious sites to (127.0.0.1 www.badsite.com)
Will this make all calls to those sites hit my IIS and make it load a default page?
Is there a way to still block these sites via HOSTS without hitting IIS?
On Win 7 pro.
Yes, all calls to those sites will hit your IIS instance. IIS might return a default page, or a "file not found" page, or if it has an actual page it might return that.
127.0.0.1 is used because it always points to the local machine, which prevents your computer from wasting bandwidth (and possibly DDOSing some poor victim) by trying to send these packets externally. You could try 127.0.0.2 or 127.254.254.254, which would work IIS is listening on 127.0.0.1 specifically or 127.0.0.0/24 rather than on every address on the loopback interface.
There isn't any other address guaranteed to not reach the public Internet, although you may be able to set one up yourself by locally blocking outgoing packets to 192.0.2.1 or the like in your firewall.
Other options for ad blocking include using a local proxy which would return HTTP 404 or the like for blocked URLs or a local DNS relay that would return NXDOMAIN for blocked domains.
Yes, as Anomie points out, they will hit your IIS and then will serve the default page or an error status or an actual page if it finds one (unlikely however).
To avoid that, I use 0.0.0.0 as the address. I've been using it with MVPS Hosts file without any issues for years now.
Also, as this post suggests, you can use 0 too (any invalid ip will do I guess)
Both of these will be a bit faster as they will avoid the wait for timeout on 127.0.0.1.
Another option would be to run IIS another port. If you are running behind a firewall or something like a home router, you could set it to port forward port 80 for incoming requests to your alternate port. (If you're using IIS inside, you'd need to go to http://[your ip address]:[alt port])

Local IIS, how do I map a URL with a port number?

I'm runnning IIS 7 on my local dev machine. My website is up and running. To access the website, I need to enter the url with the port number in the browser's address bar (www.ScoobyDoo.dev:91). What do I need to change so I only need to enter the www.ScoobyDoo.dev portion of the url? I've done this before but I'm drawing a blank. Port 80 is hosting a different website so I can't just move this one to the default http port.
Thanks!
If you want multiple sites to reside on the same IP address then you need to use HTTP Host Headers.
Provided that your existing website doesn't use SSL then you can use host headers. To configure host headers in IIS7 you modify the "Bindings" (there's a menu item for this in the right hand side Actions pane for the site):
You want to add/edit your bindings for each site that resides on the same IP address, for example for your scoobydoo.dev site:
The caveat here is that if you have users already browsing your first site by IP address then they will need to be redirected to the site using its domain name.
You can do this by adding a site bound to the raw IP address and creating a HTTP Redirect.
I'm not sure what you're expecting to do here. If something else is binding to port 80, and your web server is binding to port 91, then you'll need to specify port 91 in the web browser when making a request to the server. By default, without being explicitly given a port in the address, a web browser will make the request on port 80 (or 443 for SSL).
You might be able to add an entry to your hosts file (c:\windows\system32\drivers\etc\hosts) where you map the non-specified port version to the specified port version, but I don't think it'll work. That file is for DNS resolution, not port mapping. Worth a try though, I suppose.
Can you clarify a bit on what exactly you're expecting? Or what you think you may have done before? I wonder if you're not giving us the whole picture here.

Resources