Help with virtual host (SOLVED!)
System: Debian 6
I am a new user and read the guide on how to set up virtual host on apache here at Linode. I like to have another approach and need help setting it up correctly.
What I want
One main public web folder (/var/www)
symbolic links in /var/www to the user home folder
Three setups, dev, test, and produktion (dev.grytet.eu, test.grytet.eu, grytet.eu)
Separate logs (error.log, access.log for: dev, test and production
Not now, but eventually use SSL
My problem
When I enter a subdomain in the URL like test.grytet.eu I get error that it can not find it. If I enter dev.grytet.eu it says it is parked at my registrator. If I enter only grytet.eu it works as intended. How can I make it work for test and dev aswell?
What I have done
Pointed my domain with A record
Pointed my subdomains with CNAME (just recently, perhaps it has not resolved yet, and that is why I get the faulty behaviour).
I have created separated log files for dev, test, and production
I have turned of default virtual host
I have created a new virtual-host file for my site
I have made symbolics links to diffrent part in the users public folder (In virtual host file they are called mainpublic, devpublic, and test_public
Restarted apache
The virtual-host file
# domain: grytet.eu
# public: /var/www (symbolic linked to user home directory)
# Main
<virtualhost *:80="">ServerAdmin webmaster@localhost
DocumentRoot /var/www/main_public
ServerName www.grytet.eu
ServerAlias grytet.eu
<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 ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined</virtualhost>
# Test
<virtualhost *:80="">DocumentRoot /var/www/test_public
ServerName www.test.grytet.eu
ServerAlias test.grytet.eu
# Logging
ErrorLog /var/log/test/apache_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/test/apache_access.log combined</virtualhost>
# Dev
<virtualhost *:80="">DocumentRoot /var/www/dev_public
ServerName www.dev.grytet.eu
ServerAlias dev.grytet.eu
# Logging
ErrorLog /var/log/dev/apache_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog /var/log/dev/apache_access.log combined</virtualhost>
What am I missing, why can I not put in dev.grytet.eu or test.grytet.eu and get to the right place, it is working fine with grytet.eu
Will I be able to add SSL config to this later?
Regards
Martin
3 Replies
However,
Edit: ignore the "http://" text above; the forum automatically inserts this on things it thinks should be links.
I manage to solve this with help from "dcraig" in Linode IRC chat.
So this is what I wanted:
A central place where you point towards what is public
A public space in users home directory where user have full control of add and delete
Seperate space: dev.grytet.eu, test.grytet.eu, and production grytet.eu
Seperate apache loggings for the above environment
This what I did (System debian 6)
1. Disable default virtual host
sudo a2dissite default
2. Go to home directory
cd ~
3 Create public folder
mkdir public
4. Seperate folders in public space
cd public
mkdir dev
mkdir test
5. Make sure public folder has 755 drwxr-xr-x Owner everything, Others just read
chmod -R a+rx ~/public
6. Create the folder and separate log files in /var/log/dev and var/log/test
cd /var/log
sudo mkdir dev
cd dev
sudo nano apache_access.log
sudo nano apache_error.log
cd /var/log
sudo mkdir test
cd test
sudo nano apache_access.log
sudo nano apache_error.log
7. Add symbolic links in the public www folder, (in debian it is /var/www) to the user public space (dev, test, and production (public))
ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT]
Example
cd /var/www
ln -s /home/{user}/public main_public
Repeat the above step for dev and test
8. Create the new virtual host file
sudo nano /etc/apache2/sites-available/grytet.eu
9. Add this in file just created
# domain: grytet.eu
# public: /var/www (symbolic linked to user home directory)
# Main
<virtualhost *:80="">ServerAdmin webmaster@localhost
DocumentRoot /var/www/main_public
ServerName www.grytet.eu
ServerAlias grytet.eu
<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 ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined</virtualhost>
# Test
<virtualhost *:80="">DocumentRoot /var/www/test_public
ServerName www.test.grytet.eu
ServerAlias test.grytet.eu
# Logging
ErrorLog /var/log/test/apache_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/test/apache_access.log combined</virtualhost>
# Dev
<virtualhost *:80="">DocumentRoot /var/www/dev_public
ServerName www.dev.grytet.eu
ServerAlias dev.grytet.eu
# Logging
ErrorLog /var/log/dev/apache_error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog /var/log/dev/apache_access.log combined</virtualhost>
10. Enable the new virtual host file
sudo a2ensite grytet.eu
11. Restart apache
sudo service apache2 restart
In the above, switch out my domain to your own, and change name of files and folders to your preference.
Do not forget
At your host registrator, apart from pointing your main domain, you also need to create the sub domains (dev, and test) and point them with either A or CNAME, if you use A point to your servers ip, if you use CNAME point to your main domain. Advantage of using CNAME is that it follows your main domain, so if you ever change your host or ip, you just need to point your main domain to the new place.
Why this approach
On debian system, normal user can not write to /var/www, so uploading and deleting files was a no go. From what I read it was not advised to add a normal user to the www folders user group and let that group write to it. I could just have used the user home directory as DocumentRoot, putting a symbolic link however gave me more of an overview.
Note
If you want for instance
As a final word - If you have any suggestion on improvement, please let me know!
Regards
Martin