0

Greetings and please excuse me if this is a very basic question.

The problem:

Currently I have bought a domain (crazywebsite.com) from Godaddy.com and I have an unmanaged VPS in Site5.com.

I have set up a LAMP stack (Debian, Apache2, MySQL, PHP Laravel) in my my Debian machine in Site5.com and currently I have my IP and website look and accessible like this:

292.168.0.1./website (Just an example IP)
292.168.0.1./forum

The question:

How I can achieve the following?

crazywebsite.com => 292.168.0.1./website
forum.crazywebsite.com => 292.168.0.1./forum

So when you write down the domain I bought you see the website's content (instead of accessing it via the IP link of course).

Any ideas or links how to do this?

Currently I have tried the following:

Added settings in:

/etc/apache2/sites-available/default

to:

# website
 <VirtualHost *:80>                                                              
     ServerName crazywebsite.com                                                                      
     ServerAlias crazywebsite.com                                                   
     DocumentRoot /var/www/website                                       
 </VirtualHost>

 <VirtualHost *:80>                                                              
     ServerName www.crazywebsite.com                                                                      
     ServerAlias www.crazywebsite.com                                                   
     DocumentRoot /var/www/website                                       
 </VirtualHost>

 # forum
 <VirtualHost *:80>                                                              
     ServerName forum.crazywebsite.com                                                                      
     ServerAlias forum.crazywebsite.com                                                   
     DocumentRoot /var/www/forum                                       
 </VirtualHost>

 <VirtualHost *:80>                                                              
     ServerName www.forum.crazywebsite.com                                                                      
     ServerAlias www.forum.crazywebsite.com                                                   
     DocumentRoot /var/www/forum                                       
 </VirtualHost>

Thahk you in advance!

Edit:

As suggested by @Sven, I had made my A records in GoDaddy.com. Can anyone confirm this is correct? I have created two domains NS1 and NS2 for name servers (just in any case) and one "referrals" which I will be needing as a subdomain. enter image description here

Am I required to do any other settings on my Debian server (like BIND9 and so on?) or I just need to wait until the DNS get updated.

EDIT:

These settings have WORKED. Now the only problem I have is that I cannot point http://crazywebsite.com to 123.456.789.000/mywebsite. Instead, it always shows the root folder "/". Any suggestions?

1
  • Another detail: You need to create the nameservers MANUALLY at your own machine via the console, as far as the technical support told me. I will let you know once I manage how it is done. Dec 11, 2014 at 11:54

3 Answers 3

1

You need to add DNS records for

  • crazywebsite.com
  • www.crazywebsite,com
  • forum...
  • www.forum...

to your DNS zone in the GoDaddy control center, e.g. with an A record for crazywebsite.com and CNAMEs for everything else, pointing back to crazywebsite.com (but four A records would also work).

Instead of adding two vhosts per site (/website and /forum), you should do the following:

<VirtualHost *:80>                                                              
     ServerName  crazywebsite.com                                                                      
     ServerAlias www.crazywebsite.com                                                   
     DocumentRoot /var/www/website                                       
 </VirtualHost>

 # forum
 <VirtualHost *:80>                                                              
     ServerName forum.crazywebsite.com                                                                      
     ServerAlias www.forum.crazywebsite.com                                                   
     DocumentRoot /var/www/forum                                       
 </VirtualHost>
3
  • So, it's a bad idea to add both naked domain (without WWW) and WWW versions? Dec 11, 2014 at 10:22
  • 2
    It's useless. This is what the ServerAlias directive is for.
    – Sven
    Dec 11, 2014 at 10:25
  • I did these, please refer to my attached screenshot. Should I do any other settings in order for the website to be accessed or I just need to wait "up to 48h" in order to see the results? Dec 11, 2014 at 13:17
0

Sven suggested adding "forum" and "www" records, pointing at your Site5 VPS. You need those and not "ns1" and "ns2" - GoDaddy is currently your name server so don't worry about doing your own DNS yet.

The Apache config suggested by Sven is completely sufficient. You almost certainly already have in your ports.conf:

NameVirtualHost *:80
0

I have solved my problem and here is the solution for everyone who needs it:

1. Bind your domain to your IP in the Debian server

First you need to bind your domain name in your Debian machine. This way your Debian server knows that it needs to respond to this domain. Open and edit /etc/hosts file to the following:

127.0.0.1               localhost.localdomain localhost                                                                                                                   
123.456.789.000         crazywebsite.com # of course, in stead of 123.456.789.000 you type the IP of your Debian server

2. Set up virtual hosts for domains and subdomains.

Then you go in your apache settings and setup your domain and subdomain virtual hosts. By doing so, you will be able to point each domain to which exact folder in your server will point. Example:

crazywebsite.com => 292.168.0.1./website forum.crazywebsite.com => 292.168.0.1./forum

To do this you need to open the file /etc/apache2/sites-available/default and edit it with the following:

# This is the default  content of the file
<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www/
        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /var/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>

        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
                AllowOverride None
                Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
                Order allow,deny
                Allow from all
        </Directory>

        ErrorLog /var/log/apache2/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn

        CustomLog /var/log/apache2/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>
# END: Default content of the file

# Your custom domain and subdomain content below this line
# website
 <VirtualHost *:80>                                                              
     ServerName crazywebsite.com                                                                      
     ServerAlias www.crazywebsite.com                                                   
     DocumentRoot /var/www/website                                       
 </VirtualHost>

 # forum
 <VirtualHost *:80>                                                              
     ServerName forum.crazywebsite.com                                                                      
     ServerAlias www.forum.crazywebsite.com                                                   
     DocumentRoot /var/www/forum                                       
 </VirtualHost>

3. Making sure your domain with "WWW" and without "WWW" point to the same folder.

This was a problem which I got after doing all these steps. Only my www.crazywebsite.com pointed to /var/www/website, but the crazywebite.com version still pointed only to /var/www.

The solution is to go to the following directory:

/var/www/

and create a .htaccess file which will allow both when you type "crazywebsite.com" and "www.crazywebsite.com" to redirect to your /var/www/website folder. ServerName crazywebsite.com ServerAlias www.crazywebsite.com UseCanonicalName On

RewriteEngine     On
RewriteCond %{HTTP_HOST}   !^crazywebsite\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://crazywebsite.com/$1 [L,R]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .