landed
By:
landed

Temporary test domain name or way to achieve this

June 19, 2017 95 views
LEMP Ubuntu 16.04

Hi
I created a multi install with a single website and was able to do that because there was a working IP address.
Now I have 1 site there however I can't use the ip address (or can I) to go to the NEW folder for the new site to test.
In previous hosting scenarios I was able to turn on what was called a testing url which gave access to a folder. I tried this in my sites-available block..rewrite ^caribbean-diving.com/newsite$ var/www/newsite.com redirect;
This didn't work as the old site just 404'd

I have also tried to edit the /sites-available/digitalocean file which as I understand is the default from my one click install of LEMP. So I thought this could be the file the dedicated IP address could root through first...so I pointed the root directive to my new sites folder of that but it didn't do anything and I still get to my initial website.

How to achieve this?
Thanks

3 Answers

Out of interest what operating system are you using locally on your own computer?

If you're using Windows you can edit the file C:\Windows\System32\drivers\etc\hosts and add a line like this:

2.2.2.2 testdomain.com

Replace 2.2.2.2 with the IP address of your droplet.

testdomain.com will then map to your droplet from your local work station, bypassing any external DNS lookup.

Setup a new virtual host under sites-enabled.conf for testdomain.com and away you go.

  • I am using a mac.
    Yes I thought about my local hosts file but as I understand it this just allows me to access my droplet with a local custom domain.
    I have no problem accessing the droplet through the IP...am I missing something?
    What I think or feel I need is a way to access the NEW FOLDER.
    I am not sure what makes the 'digitalocean' inside sites-available as the default but would think I could use that to point to my new site folder.
    Thanks for this insight :)

    • In /etc/apache2/sites-available you should have a file called something like caribbean-diving.com.conf which will contain the virtual host for that domain, i.e.:

      <VirtualHost *:80>
      ServerName caribbean-diving.com
      DocumentRoot /var/www/caribbean-diving.com
      </VirtualHost>
      

      Create a new file in /etc/apache2/sites-available called newsite.com.conf or similar with the following contents:

      <VirtualHost *:80>
      ServerName newsite.com
      DocumentRoot /var/www/newsite.com
      </VirtualHost>
      

      However, if you want caribbean-diving.com/newsite to show the virtual host for newsite.com you could redirect it:

      <VirtualHost *:80>
      ServerName caribbean-diving.com
      DocumentRoot /var/www/caribbean-diving.com
      Redirect /newsite http://www.newsite.com/
      </VirtualHost>
      

      If you don't want to redirect it but actually want it to show under http://caribbean-diving.com/newsite, I'm not sure how you do that with mod_rewrite. What you want to do is rewrite the URL to a different virtualhost - I'm not sure how you do this or if you have to use some kind of proxypass configuration, but it seems complicated for what you require.

      • Thanks again - yes this is the kind of thing that could work. I didn't mention I was using NGINX though but principle could be the same so this redirect needs to redirect to a local folder hence..

        rewrite ^caribbean-diving.com/newsite$ var/www/newsite.com redirect;
        

        So theory is we use the domain caribbean-diving.com to get to the DO DNS and then it resolves to my droplet. At this point the redirect should work to redirect to the local folder (other website) but it doesn't catch the redirect it just 404's

        • I think that's because you can't rewrite like that. It has to be relative your document root I believe.

          It will be looking for this folder:

          /var/www/caribbean-diving.com/var/www/newsite.com

          Which obviously doesn't exist.

          A better option might be to simply create a symbolic link:

          ln -s /var/www/newsite.com /var/www/caribbean-diving.com/newsite

          • Sorry yes that was a typo missing the "/" in this post.
            Where would I write a symbolic link? Is that part of the nginx config file.

A better option might be to simply create a symbolic link.

A symbolic link is part of your file system (nothing to do with Apache or nginx).

It creates a "virtual" directory which maps to a directory elsewhere in the file system.

You would run this via the command line (make sure the newsite folder doesn't already exist):

ln -s /var/www/newsite.com /var/www/caribbean-diving.com/newsite

This creates a "vitual" link under /var/www/caribbean-diving.com/newsite which maps to /var/www/newsite.com

Anyone visiting http://caribbean-diving.com/newsite will see the contents of /var/www/newsite.com

  • That sounds like a handy workaround but my folder isn't empty and it leaves a bit of confusion for me coming back here say in 6 months...so I would like to get the server blocks right.

In my case what seems to have been lacking is a default server and now it seems to be working and what @DigitalCarrot would have got had I posted my server block code...many thanks to you @DigitalCarrot

SO in my default site block I now have this

server {
        listen 80 default_server;
        listen [::]:80 default_server;

Vs

server {
        listen 80;
        listen [::]:80;

Now when I use the IP address remotely I can access what this default site points to...

Have another answer? Share your knowledge.