Howto: Virtual Hosts in Synology DS211j (Apache)
Sometimes, when developing for a web site for instance, you may need to get the site running in a virtual host in Apache, in order to test how it functions in a production environment. If you don’t use the virtual host technique, you need to manually insert paths in order to get for example CSS styles working properly. That is because in a production environment it is common that the references paths start from the domain and not having a directory in the beginning. Follow these steps to enable virtual hosts in Synology DS211j.
The Easy Way
I assume you have enabled Web Station in the Admin Control Panel → Web Services. Right there you’ll find Virtual Hosts button that will take you to the virtual hosts list where you can create new virtual hosts. Just hit “Create” and it will ask you four things: the name of the subfolder, hostname, protocol and port. The subfolder needs to be in /volume1/web/ directory. Hostname can supposedly be anything.
Once created, the new virtual host answers from <your-synology’s-ip>:<port>. In my case this is 192.168.1.2:8082. That’s it!
The Hard Way
You can also set up virtual host using Apache’s configuration files as normally. The configuration files are located in:
/usr/syno/apache/conf/ and first you need to enable virtual hosts in httpd.conf-user. Remove the comment from the line beginning with “Include”:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
There is no such file so we need to create it:
vi /usr/syno/apache/conf/extra/httpd-vhosts.conf
Insert into the file:
Listen 8082 NameVirtualHost *:8082 <VirtualHost *:8082> ServerName <anything> DocumentRoot /volume1/web/<subdirectory> </VirtualHost>
After saving the configuration files you need to restart Apache:
/usr/syno/etc.defaults/rc.d/S97apache-user.sh restart
If it does not work, you may want to turn Apache error logging on, which is disabled by default. This can be done in httpd.conf-user:
ErrorLog /var/log/httpd-error-user.log
# ErrorLog /dev/null
When I enabled virtual hosts and defined my virtual host as described, I got a weird error:
Warning: Unknown: open_basedir restriction in effect.
File (index.php) is not within the allowed path(s):
...
I tried everything, tweaking open_basedir setting, include paths, toggling PHP safe mode, etc. and nothing helped. Then I realized that this is caused by the virtual host directory being in wrong place. For some reason it cannot be in the user home:
/volume1/homes/<username>/www/<subdirectory>
Move it to the main web directory /volume1/web/<subdirectory> and you will get rid of the error.
That’s it, enjoy!


February 5th, 2013 at 06:12
Thanks for the article. I do have one followup question. How do you access the virtual host site from the Internet? In other words, what IP address or domain name would you use?
Thanks,
Kelly
February 5th, 2013 at 08:21
Hi Kelly,
Thanks for the comment. Unfortunately, when accessing your virtual hosts from the outside, you have to stick to your real domain as you cannot tamper with the official name servers. This is where the different ports come in handy. In other words, you may access your virtual hosts this way: yourdomain.com:8085. I do web programming for various clients and they often want to take a look at the site before I go live with it, so it is really nice to be able to give the client an address where the site is up and running and they can click it through to see how it functions. I hope this helps!
Of course normally you don’t have a domain if your NAS is at home. This is where you need to use some of the dynamic DNS services like dyndns.com.
February 5th, 2013 at 08:45
Thanks for your reply. I’m basically trying to do the same thing you’ve achieved. I setup my DS 1512+ for use as a developmental server for website design and although I can get Virtual Hosting to work internally, I’m unable to get it to work via the Internet. I’m using Synology’s MyDS to handle my dynamic IP address.
Does it take a while for the DNS to update?
February 6th, 2013 at 12:04
I believe in this case it is a matter of router configuration.
March 19th, 2013 at 08:29
I have just setup a virtualhost but I have encountered a weird problem.
I setup virtualhost in D207+ by easy way.
eg. myDomainSubfolder myDomain.com 80
when I go to myDomain, it does not show up, it show the root of the web instead.
if I go to myDomain.com/myDomainSubfolder, it does show up content, thus, it is not directing to the subfolder but the root instead.
Did I missing something in settings?
Any clue is appreciated.
Much thanks.
March 19th, 2013 at 13:37
I have figured out the cause of the problem.
Although I have registered the Domain, I set it up in freedns.afraid.org for Nameservers. And thus
http://www.myDoamin.com and myDomain.com must be setup in Synology Apache Virtual Servers separately
i.e.
myDomainSubfolder myDomain.com 80
myDomainSubfolder http://www.myDomain.com 80
they can share the same subfolder or not share,
if one of them is not set, eg.
if http://www.myDomain.com is not set, it will be directed to the root of the webserver
For more information about it, people could read
search about “www or without www” in the web, there are a few explanations.
Many thanks.
March 21st, 2013 at 09:45
Thank you sorcererapp for the explanation. I thought it had something to do with the normal domain and the sub-domain clashing. Thanks for the research!
August 3rd, 2014 at 21:58
I currently have a virtual hosts setup on DS214play. I can access the site from within my network (http://internal IP address:8085), but not from outside my network (ie. (http://external ip address:8085) Is it possible to get to a virtual host from outside your network without registering a domain name? Any help would be appreciated. Thanks
November 8th, 2014 at 14:46
Hi,
I assume you edit the config filed in Text Editor. How do you get to the files to edit them?
I can see how to edit standard text files on the NAS volume but not system config files.
July 13th, 2017 at 11:52
I think the reports are just Drastic changes to an IRA over the course few days or less I hope to be notified about
August 26th, 2017 at 19:58
Hello,I read your blogs named “Howto: Virtual Hosts in Synology DS211j (Apache) | Arinium Blog” on a regular basis.Your writing style is awesome, keep it up! And you can look our website about proxy server list https://proxylistdaily4you.blogspot.com/.