Score:-1

I need to hit website with server_ip/path_to_index.html

dz flag

I am testing @media statements in a locally hosted website I am building but for the life of me can't hit the site with site_IP/virtual_host_name.

If I have access to the hosts file I simply add (site name) localtest.com into the file along with the IP of the site 192.168.1.X as per normal and all works well. I don't have a rooted phone (my contact wants his site optimised for phone access) so cannot edit the dev hosts file to make the necessary changes. I realise I can use the F12 dev facility to pull different size sites locally but would like to use http://localtest.com as (in my mind) it's the real McCoy. For the life of me I can get it working. I have tried

  1. http://192.168.1.X/localtest.com
  2. http://192.168.1.X/var/www/localtest.com (doc root is /var/www in sites-enabled)

and always get a 404. I have checked the access with Wireshark and curl. The request is getting to the server and is answered with the 404. I have an old Windows laptop that confirmed this issue... as soon as I populated the hosts file with the correct entry 192.168.1.X localtest.com

it started displaying properly - using http://localtest.com

UFW isn't blocking port 80

If I http://192.168.1.X I get the UBUNTU Success Page. It's going to be something so stupid. I am sure I have done this before

I hope you are still awake after reading this and you are able to suggest something, I am pulling my hair out.......

Thanks

Kev

Score:1
cn flag

The problem you're having is that your client isnt sending the "Host" request header that you want. The webserver is getting a request for the host {ip_address} and since it doesnt match a configured server_name (or other name virtualhost config) its just serving the default.

Server side fix

The easy way to fix this is to make "localsite.com" the default site, or add the ip address to the server_name config.

Client side fix

Client side, you'll have to send the right Host header. On the command line you could just use something like curl http://ip.ad.dr.es -H "Host: localtest.com", I've never used anything like this, but you could try a browser plugin to modify the headers it sends - https://addons.mozilla.org/en-US/firefox/addon/modify-header-value/ seems to do it (but be careful, anyone can make browser plugins, even baddies :) )

ws flag
....or just provision DNS records
Kevin Ridsdale avatar
dz flag
Thanks so much for the reply. I can't do anything on the client side configuration (as I don't have a rooted phone) Also I have never done my own DNS - now's the time to learn !!!! Thanks again.
Score:0
in flag

Most web servers support name based virtual hosting and can display different content based on the hostname provided by the web browser visiting that server.

You have probably set up more than one name based virtual host and content for localtest.com will only get displayed when that domain is used.

A different or default name based virtual host, with different content, will get used when the web browser provides a different hostname or the servers IP-address is used.


Your best solution:

  • Get your own domain i.e. example.com

  • Set up DNS records such as for example www.client-name.example.com , dev.client-name.example.com and www.otherclient-name.example.com to point to the IP-address of your public web server and/or your development system(s)

  • Set up name based virtual hosts with those valid host names

Then you don't have to muck about with hosts file entries, can always easily use a conventional URL and you can for example also get valid TLS certificates.

  • Bonus If you're (also) using a public web server consider setting up access controls (i.e. grant access from your own IP-address and/or set up basic authentication to require a valid username/password for access) and then your clients can visit their demo sites as well without a need to set up hosts file entries.

As alternative solution alternative is to ensure that localtest.com becomes the default virtual host. Typically in Apache httpd that happens when you disable the 000-default.conf (and/or all other virtual host entries or) or by making the localtest.com the first entry that gets loaded by giving the configuration file a name that gets lexicographically ordered first i.e. name the config 0000-localtest.conf instead of localtest.conf

Kevin Ridsdale avatar
dz flag
Thanks very much for the reply. I shall read and ingest the suggestions. Thanks again
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.