Viewing site at ip address

Is there a way I can see / test a site out on my Linode before I implement the nameserver change that will point it to my server?

I've copied an entire site to my Linode but I'd like to test it out before putting the site live from this box.

3 Replies

Setup a HOSTS file on your local system for that domain pointing to your Linode IP.

Ok I added this entry

178.79.xxx.xxx domain.net

and get an internal server error (probaly since I have still to config the htaccess etc). If I just punch in the IP, I get one of the sites that hosted on my linode at that IP. Not sure why it's showing that site.

Does the entry in the hosts file automatically "map" my request to the folder containing the domain.net site? I have about half a dozen sites at that IP.

Finally, the CMS powering this site needs a bunch of server paths in its configuration. Usually this is something like www/domain.net/… - would this work when using the hostfile trick?

In my .htaccess I have a RewriteBase which would be /domain.net/ once the NSs are changed - will this work with the hostfile trick?

@stef25:

Does the entry in the hosts file automatically "map" my request to the folder containing the domain.net site? I have about half a dozen sites at that IP.

The hosts file is independent from how the server maps inbound requests. It lets you permit a production name to be sent to the server without having it in DNS, but how that gets mapped to any local directory structure is entirely under the control of the web server configuration.

In all cases, a browser takes a URL and turns the host portion into a target address (unless it's already an address) of a server to talk to. When talking to the server at that address, the browser passes across its idea of the "host" in the URL (generally exactly what was entered in the URL by the user) as part of the request, in a Host: header.

When a web server is configured to conditionally supply a response for a virtual site (e.g., not just using a single global configuration), it uses that Host: header to decide which virtual host is being requested.

Typically in production the name published in DNS and thus used by browsers matches your virtual host configuration in the server.

When testing without DNS, you can either temporarily configure your web server to check for an IP address for the virtual host, or as you are doing, have a local mapping of the right name to an address.

In your case, when you used the IP address directly in the browser, I'm guessing it didn't match any virtual host definition in your web server, so the server fell back it's default site. So I expect you have a default site configured on that server (which may in fact just be a default tree that was installed when the server was installed).

By having "domain.net" in the host file, you can use that host name in the browser URL, and that's the name that will be seen by the server in the Host: request header. All URL paths are relative to the host, so yes, this will cover any child URLs beneath domain.net. But it's up to you to have the server properly configured so that requests to domain.net are mapped where you want.

If your virtual host is actually configured as "www.domain.net" then you have to make sure you use that full name in the local hosts entry or else you'll fail to match your virtual host on the server side.

If you want both www.domain.net and domain.net to work you can put both in the hosts file, but you'll also need to ensure your server is configured to match both (or redirect one to the other). There are other threads here related to that.

Note that depending how you do the testing, you may also have to make sure that any applications running on your web server, if they use redirects, are configured for the proper server name, since URLs they may supply to the browser then need to resolve. So if, for example, you set up your hosts for domain.net, but have configured an application to use www.domain.net, you'll have problems until you add www.domain.net into your hosts file as well.

– David

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct