Jump to content

HOSTS & Local Server


Viper114
 Share

Recommended Posts

OK, so picture this. I have my own computer which is Windows 7, and a Debian desktop. On this Debian desktop is a complete copy of my employer's website that I want to test to ensure it works. I can access the front page fine by going to our WAN IP at port 81 (x.x.x.x:81). However, it's specifically designed to work only when it reads the address as www.businessname.com, otherwise there are errors all over when I explore (particularly in the back end). I figured the way to do this would be to manipulate my computer's HOSTS file to read the WAN IP and port 81 as the domain name (so when I go to www.businessname.com, it redirects me to x.x.x.x:81). However, when I do this, I still end up finding myself on the actual website as seen by the public, even though I don't want to. It doesn't seem to matter which browser I use, it's the same, the change in HOSTS still isn't being performed. This is weird because when I did the same thing for a test site on a server located elsewhere, it worked fine, so I'm not understand why this is happening other than the fact that now the test site is sitting on a server sitting 4 feet away from me.Is there something I'm missing?

Link to comment
Share on other sites

The hosts file only maps names to IPs. It doesn't map ports. Perhaps the app is also hardcoded to only work on port 80, or to be more precise, to work with whatever the default port is... if you can find an HTTP request forging program, perhaps you can trick it into doing a proper request (I'm not sure if Fiddler would work, but I mean a program of the same kind). However, that doesn't imply normal browsing, making any testing unreliable.The best way to make things work is to simply rework the program to work regardless of port. This can easily be achieved by NOT using absolute URLs on the page.

Link to comment
Share on other sites

Hmm, so it's the port that's the problem. Perhaps if I remove that and have it default to port 80, that could allow it to work. Alright, I'll see what I can do, thanks for the pointer.EDIT: OK, so there's another problem. If I just put in the WAN IP in my browser, it actually leads to a special website of ours that contains our webmail access. So unfortunately, it's no longer a simple case of having the test website use the default of Port 80 so that HOSTS will work properly. Shoot, any ideas now?

Edited by Viper114
Link to comment
Share on other sites

If the site doesn't use any absolute paths in it, you can simply put the test site back on port 81, and then just type

http://example.com:81/

to reach it.

Link to comment
Share on other sites

If you make an entry in the HOSTS file, you can override that... the only problem is you won't be able to view the live site then.You could create another host entry of course. An entry of non existent domain, like:

http://test.example.com:81/

(assuming the app is smart enough not to be dependant on the exact domain name, and be capable of just reading the "main" domain is correct)

Link to comment
Share on other sites

So you mean instead of setting it up like:x.x.x.x:81 www.businessname.comTry and instead set it up like:x.x.x.x www.businessname.com:81?I don't mind not viewing the live site for the time being, I'm mainly trying to test the test site first, and I have other ways of accessing the live site when I need it.

Link to comment
Share on other sites

More like

x.x.x.x www.businessname.com

and then access it as

http://www.businessname.com:81/

Again, the HOSTS file doesn't deal with ports. Only with name to IP matches.

Link to comment
Share on other sites

OK, I'll see what happens when I try that.EDIT: That kind of did it. By setting it up like that and then putting :81 at the end of the web address, I can get to the main page of the test site. Problem is, the links are still broken, as they keep wanting to work with www.businessname.com/whatever. The :81 is getting in the way otherwise. Seems like I may need something else in order to have the test site think it's the live site to work properly...

Edited by Viper114
Link to comment
Share on other sites

Look at your app's generated source... does it by any chance use any absolute URLs (starting with "http://") to target its own stuff? If so, make those paths relative to the domain (starting with "/") instead, and everything will work as expected on both servers.Otherwise, you'll need to have two configuration files, one specific for the test server and the other for the live server, and in it, write out the domain and port to be used... then again, if you become capable of making this part flexible, you'll be able to eliminate absolute URLs altogether.

Link to comment
Share on other sites

So, in other words, I need to do some recoding of the website. I was hoping I wouldn't, but I'll see what I can do.EDIT: Something's come up that's pushed the priority of getting the website on Amazon's service to the top. Looks like I'm just going to have to do the testing on the instance instead.

Edited by Viper114
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...