2

I have a single Digital Ocean droplet with 5 websites hosted on it via virtualhost. Everything works fine. Their domain names point to each one individually. Using Ubuntu 14.04 and Apache.

I want to add a sixth "test" site, without a domain name pointing to it. I want to use it to test out some WordPress stuff. The physical location of the home page to this site is:

/var/www/test_site/html/index.html

Let's say my server's IP address is 198.51.100.55

What do I need to do to make this home page available to anyone on the internet as follows?

http://198.51.100.55/test_site/html/index.html
kasperd
  • 29,894
  • 16
  • 72
  • 122
thanks_in_advance
  • 173
  • 1
  • 2
  • 8

2 Answers2

2

Summary: You cannot make it work for everybody unless you use a domain name. But if you just treat 198.51.100.55 as if it was yet another domain name, it will work for most users - at least for the time being.

My recommendation is to create a domain for your test site. Possible options include: acquiring a new domain, using a subdomain of one of your existing domains, using a free subdomain from one of the various providers of such domains.


The URL http://198.51.100.55/test_site/html/index.html will never be accessible to the entire internet.

There are new networks being deployed without IPv4. In order to allow clients on such networks to access IPv4-only resources techniques such as DNS64 and NAT64 are being used. If the name of your server was test.example.com the connection flow for such a client could work as follows:

  • The browser sends a query to the ISPs DNS recursor asking for the AAAA record for test.example.com
  • The ISPs DNS recursor asks the authoritative server for example.com for the AAAA record for test.example.com
  • The Authoritative server replies that no such record exists.
  • The ISPs DNS recursor falls back to DNS64 and ask the authoritative server for example.com for the A record for test.example.com
  • The Authoritative server replies with 198.51.100.55
  • The DNS recursor concatenates the prefix of one of the ISPs NAT64 gateways (let's call it 2001:db8:c481:4960:88df:da01::/96 and the IPv4 address. The result is 2001:db8:c481:4960:88df:da01:198.51.100.55 AKA 2001:db8:c481:4960:88df:da01:c633:6437.
  • The DNS recursor sends a response to the browser saying the AAAA record for test.example.com is 2001:db8:c481:4960:88df:da01:c633:6437.
  • The Browser sends a SYN packet to the NAT64 on 2001:db8:c481:4960:88df:da01:c633:6437.
  • The NAT64 converts the SYN packet from IPv6 to IPv4 by stripping of the first 96 bits of the destination IP address and substituting its own IPv4 address as source.
  • The communication continues with the NAT64 translating every packet in the TCP connection.

But the moment you try to do this with an IP address rather than a domain name, it breaks down. The browser will never send any DNS request, so it never learns that 198.51.100.55 is to be substituted by 2001:db8:c481:4960:88df:da01:c633:6437. Instead the browser will try to connect to 198.51.100.55, but the host has no IPv4 route, so the kernel will tell the browser that the server is unreachable.

The only way you can make the site available to users on such a network (without breaking anything else) is by having a domain name for your site.

If you are satisfied with making your site available only to a large percentage of the internet (which will keep getting smaller over time), then you can simply treat 198.51.100.55 as yet another domain name and configure a virtual host accordingly.

It would look something like this:

<VirtualHost 198.51.100.55:80>
    ServerName 198.51.100.55
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www
    ErrorLog ${APACHE_LOG_DIR}/error.log
    LogLevel warn
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
kasperd
  • 29,894
  • 16
  • 72
  • 122
  • Would this issue be resolved if I converted my server address to a IP v6? (Digital Ocean offers the option.) – thanks_in_advance Dec 19 '16 at 17:56
  • @user1883050 You'd still need a domain name. A server with only IPv6 cannot be recommended yet. So you would need a server with both IPv4 and IPv6. But then you would have two IP addresses, and which of them would you put in the URL? You'd need a domain name with one A record and one AAAA record such that clients can resolve whichever works from their network. Having native dual stack on your server would make access to your server more reliable for those 16% of the users who currently have IPv6. – kasperd Dec 19 '16 at 18:06
  • OK, thanks for all the suggestions so far. What if I alone (*i.e., I no longer cared if the entire internet can see it. As long as I can see it, it's enough. And if others can see it too, that doesn't bother me*) wanted to see how the site works via the real internet (*instead of testing it via Localhost on my own desktop computer*), what can I do so that a page in the `/var/www` folder is accessible (to me) via the IP address of my server, e.g. via `http://198.51.100.55/test_site/html/index.html`, instead of using a domain name? Thanks! – thanks_in_advance Dec 20 '16 at 19:21
  • @user1883050 Even in that case I think it would be more convenient to type a name in the URL rather than an IP address. It could be created either as a full domain name in DNS or as just a hostname in `/etc/hosts`. If you still want to type the IP address in the URL, you can just create a `VirtualHost` with a `ServerName` directive specifying the IP address rather than a domain name. – kasperd Dec 20 '16 at 21:17
1

Place the following before the other virtualhost definitions in your config file.

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName www.fakesite.com
DocumentRoot /var/www/test_site/html/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Then reload Apache.

bao7uo
  • 1,664
  • 11
  • 24
  • Hi again. It's causing a problem. Have a look at this image: http://imgur.com/a/XeHq3 . Basically, when someone goes to `somesite.com`, they see the directory listing at `/var/www` (instead of the homepage for `somesite.com`). Suggestions? – thanks_in_advance Dec 19 '16 at 17:34
  • Try putting it above all the others instead of below them. – bao7uo Dec 19 '16 at 17:59
  • Same problem unfortunately. Anyway, do let me know if you can think of anything. Thanks! – thanks_in_advance Dec 19 '16 at 18:05
  • I guess you reloaded apache? what does it do if you visit the IP address when you remove that section and reload apache? – bao7uo Dec 19 '16 at 18:08
  • If I remove the `... ` portion, and restart Apache, then my various domain names lead to the respective sites' homepages. If I add the portion back (at top or bottom of `conf` file), and restart Apache, then my domain names lead to the directory listing at `/var/www/`. And I've been testing by opening new instances of Google Chrome Incognito mode, so it's probably not a caching problem. – thanks_in_advance Dec 19 '16 at 18:15
  • I mean, once you have removed the `... ` can you access it via the IP? It might work, because you don't have the hostname there, it won't go to the virtual hosts, so it will go to your default document root which could be /var/www If it doesn't work, what does it give you when you use the IP and you don't have that portion?? – bao7uo Dec 19 '16 at 19:44
  • After removing that portion, `198.51.100.55` gives the home page of one of my sites (the first one listed in the .conf file). `198.51.100.55/test_site/html/index.html` gives a "Not Found" error. – thanks_in_advance Dec 19 '16 at 21:24
  • Is it a virtual host? Could you paste it up? Obviously anonymize any details you don't want to share. – bao7uo Dec 19 '16 at 21:54
  • Sure. This is the current content of my `/etc/apache2/sites-available/sites.conf` file: http://pastebin.com/0jdnFH4r , and this is the content with your original suggestion which worked great for my test site but led my domain names to the folder structure at `/var/www`: http://pastebin.com/Mq1bnPVU – thanks_in_advance Dec 19 '16 at 22:49
  • might sound crazy, but try copying one of the virtualhost blocks with a domain, and put it at the top. but change the domain to something that does not exist. then reload apache and try accessing with the IP. – bao7uo Dec 19 '16 at 23:27
  • I can reach "test site" with IP (`198.51.100.55/test_site/html/index.html `), but for the other domains, I again only get the directory listing at `/var/www` – thanks_in_advance Dec 20 '16 at 03:05
  • 1
    I meant remove this section completely - ` DocumentRoot /var/www/ ` and put a copy of one of the domain blocks at the top with your test site document root and a fake domain. – bao7uo Dec 20 '16 at 14:17
  • OK that works, I have to enter `198.51.100.55` to get to my test site's home page. 2 Questions: Why does it work? And does this mean one can only have a single test site? Thanks! – thanks_in_advance Dec 20 '16 at 19:11
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/50422/discussion-between-user1883050-and-phpaul). – thanks_in_advance Dec 21 '16 at 00:37
  • OK. I have edited my answer to reflect the solution. – bao7uo Dec 21 '16 at 01:09