• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Virtual Subdomains (Wildcard) vs. real Subdomains

MikeDiDo

New Pleskian
Hello,
I need some help with a problem of Virtual Subdomains vs. Real Subdomains:

Setup:
- dedicated Server at 1and1 with CentOS and Plesk 10.02
- Domain: example.com
- real Subdomain: blog.example.com (created via Plesk)
- PHP system running in main domain example.com (httpdocs folder)
- PHP system allows user to create user specific website with URL user.example.com
- request for user.example.com is redirected via Wildcard to php system in httpdocs folder
- Wildcard created via A-Record (*.example.com) and Vhost.conf (ServerAlias *.example.com)

Example:
User Donald creates his website with URL http://donald.example.com. The request for the subdomain is processed correctly, reaching the php system that returns the website.

Problem:
The real subdomain blog.example.com is processed like just another virtual subdomain, reaching the php system. But it should redirect to the subdomain/blog/httpdocs folder!

Questions:
a) Some sources claim that the Wildcard-A-Record (*.example.com) will be processed if no other DNS record (like the blog-A-Record blog.example.com) matched the request. Some people just claim the opposite. Can anybody confirm the order of processing DNS records?

b) Looking at my httpd.include I found the virtual host entry for the blog.example.com below the virtual host entry for example.com:80 and example.com:443. The example.com:80 is showing the <include> of the *.example.com. That way the *.example.com catches any request already before the blog.example.com is processed. Changing the order of the httpd.include entries manually will be overwritten by plesk. How can I change the order inside the httpd.include then?

c) Some sources suggest to create a ZZZ_Wildcard subdomain as a catch-all. However, the zzz_wildcard would redirect to the subdomains/zzz_wildcard/httpdocs folder. But my PHP system needs to run in the principal httpdocs folder. Is there a chance to redirect form the subdomains/zzz_wildcard/httpdocs folder to the principal httpdocs folder via .htaccess?

d) Any other idea of how to use virtual subdomains and real subdomains at one domain?

Any idea will be highly appreaciated as I already read through more than a hundred blog posts and pages without any of the suggested solutions solving my problem.

Thanks,
Mike
 
Hi Mike,

I can point you in the right direction. You want to remove the wildcard from plesk, and create the wild card virtual host option using a zzz_wildcard.conf file. I think the confusion you are having with the zzz_ method is you cannot create this through the control panel. It must be created and placed in the proper directory on your server (I believe it is /etc/httpd/conf.d/ ).

In this file you want something along the lines of

<VirtualHost *.example.com:80>
DocumentRoot "/path/to/example.com/httpdocs"
ServerName *.example.com
</VirtualHost>

Edit: you may want to look in the actual httpd.include for your main domain to see what options you need set here if you run into errors

by manually creating the file, and naming it with the zzz_ prefix, you will ensure it is loaded last, and will not override your plesk created "real" subdomains.

Good luck,

Dave
 
Problem solved!!!!

First of all, I would like to thank Dave for pointing me the right way and solving my problem. As I spend hours searching for the solution without any luck, I will repeat the solution here so it might help all other desperate people out there. Here is what I did (following Dave's path):

1. I removed the wildcard A-record and vhost.conf file that I created beforehand (most manuals for virtual subdomains with Plesk suggest to create *.example.com A-records and vhost.conf files. DO NOT do that.)
--> Status: all real subdomains (for example, blog.example.com) were working without problems. Virtual Subdomains were not.

2. I opened the httpd.include file in a text editor. If you access your server via SSH and root, you will find the file at /var/www/vhosts/[yourdomain.com]/conf/

3. In the httpd.include file, I looked for these lines:
<VirtualHost [your IP address]>
ServerName yourdomain.com:80
ServerAlias www.yourdomain.com
....
</VirtualHost>

Attention: Be aware that there might be one virtual host for yourdomain.com:80, yourdomain.com:443 and any subdomain. Look for the yourdomain.com:80 virtual host.

4. I copied all lines between <VirtualHost [your IP address]> and </VirtualHost> to a new file I called zzz-wildcard.conf.

5. I changed the line "ServerAlias www.yourdomain.com" to "ServerAlias *.yourdomain.com".

6. I transferred the zzz-wildcard file to /etc/httpd/conf.d at my server.

7. I updated with /usr/local/psa/admin/sbin/websrvmng -a (via SSH comand line) and restarted the apache server via Plesk.

--> Status: Everything (real subdomains, virtual subdomains, www.example.com, etc.) works as it should work.

8. As I am using more than one domain, I repeated the process for each domain and copied the Virtual Host from all httpd.include files into the same zzz-wildcard.conf.

That's it. I really hope it will work for all of you as it did for me. Once again, thanks to Dave for his help.
 
You can do something similar like this for all domains on your server (or substitute one domain for the $DOMAINS)

DOMAINS=$(mysql -uadmin -p`cat /etc/psa/.psa.shadow ` psa -Ne "select Name from domains;")

for DOMAIN in $DOMAINS ; do
echo "ServerAlias *.$DOMAIN" >> /var/www/vhosts/$DOMAIN/conf/vhost.conf;
echo "ServerAlias *.$DOMAIN" >> /var/www/vhosts/$DOMAIN/conf/vhost_ssl.conf;
done

/usr/local/psa/admin/sbin/websrvmng -va
 
adding external httpd.conf to plesk

Hello,

I have a similar problem, but related to a sub-domain only.
It is described below. Please help.

I am using Plesk 10.2 with centOS 6.2 on my server.
I have a domain - www.openlx.com, which is working fine.
I have created, through plesk, as usual, a sub-domain koha.openlx.com, which is showing up fine.

Now, I installed Koha Library application and the whole process has been successful.
This generates its httpd.conf (/etc/koha/koha-httpd.conf) file which needs to be included in plesk, and that is where I am facing an issue.
The following commands, rquired by Koha were executed, with no errors :
export KOHA_CONF=/etc/koha/koha-conf.xml
export PERL5LIB=/var/www/vhosts/openlx.com/koha/lib


I created a link vhost.conf in the following directories :

/var/www/vhosts/openlx.com/conf
and
/var/www/vhosts/openlx.com/subdomain/koha/conf

and then gave the following command :
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain koha.openlx.com

there is no error, but the domain does not get added (the application is not visible, though on a linux server, without plesk, this is enough).

Then, I copied the /etc/koha/koha-httpd.conf, as vhost.conf file at the following locations :
/var/www/vhosts/openlx.com/conf
and
/var/www/vhosts/openlx.com/subdomain/koha/conf

and then gave the following command :
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain koha.openlx.com

there is no error, but the domain does not get added (the application is not visible, though on a linux server, without plesk, this is enough).

I wonder what is the mistake that I need to correct.
Please help.
===========================

The /etc/koha/koha-httpd.conf has the following details :

# Koha Apache Configuration Directives

#NameVirtualHost *

## OPAC
<VirtualHost 173.193.109.146:80>
ServerAdmin [email protected]
DocumentRoot /var/www/vhosts/openlx.com/koha/opac/htdocs

<Directory /var/www/vhosts/openlx.com/koha/opac/htdocs/>
php_admin_value open_basedir "/var/www/vhosts/openlx.com/koha/opac/htdocs:/php/includes" </Directory>

## ServerName humanist.netshooter.com
ServerName koha.openlx.com
# ServerAlias opac.mydomain.com
ScriptAlias /cgi-bin/koha/ "/var/www/vhosts/openlx.com/koha/opac/cgi-bin/opac/"
ScriptAlias /index.html "/var/www/vhosts/openlx.com/koha/opac/cgi-bin/opac/opac-main.pl"
ScriptAlias /opac-search.pl "/var/www/vhosts/openlx.com/koha/opac/cgi-bin/opac/opac-search.pl"
ScriptAlias /search "/var/www/vhosts/openlx.com/koha/opac/cgi-bin/opac/opac-search.pl"
ErrorLog /var/log/koha/koha-opac-error_log
# CustomLog /var/log/koha/koha-opac-access_log combined
# TransferLog /var/log/koha/koha-opac-access_log
SetEnv KOHA_CONF "/etc/koha/koha-conf.xml"
SetEnv PERL5LIB "/var/www/vhosts/openlx.com/koha/lib"
SetEnv MEMCACHED_SERVERS ""
SetEnv MEMCACHED_NAMESPACE ""

<IfModule mod_gzip.c>
mod_gzip_on yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_can_negotiate yes
mod_gzip_update_static No
mod_gzip_temp_dir /tmp
mod_gzip_minimum_file_size 512
mod_gzip_maximum_file_size 1000000
mod_gzip_maximum_inmem_size 1000000
mod_gzip_handle_methods GET POST
mod_gzip_item_exclude reqheader "User-Agent: .*Mozilla/4\..*\["
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader Content-Type:image/*
mod_gzip_item_include file \.js$
mod_gzip_item_include mime ^application/javascript$
mod_gzip_item_include mime ^application/x-javascript$
mod_gzip_item_include file \.php$
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include file \.css$
mod_gzip_item_include mime ^text/css$
</IfModule>

<IfModule mod_deflate.c>

# Compress content with type html, text, and css, ...
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript

DeflateCompressionLevel 9

# Properly handle old browsers that do not support compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio

LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
<IfModule mod_headers.c>
#properly handle requests coming from behind proxies
Header append Vary User-Agent
</IfModule>
</IfModule>


# Repeat this virtualhost stanza changing the following environment vars to
# create multiple OPAC interfaces with custom css and/or search limits:
# SetEnv OPAC_CSS_OVERRIDE mystyle.css
# SetEnv OPAC_SEARCH_LIMIT branch:CODE
# SetEnv OPAC_LIMIT_OVERRIDE 1

Options +FollowSymLinks

ErrorDocument 400 /cgi-bin/koha/errors/400.pl
ErrorDocument 401 /cgi-bin/koha/errors/401.pl
ErrorDocument 403 /cgi-bin/koha/errors/403.pl
ErrorDocument 404 /cgi-bin/koha/errors/404.pl
ErrorDocument 500 /cgi-bin/koha/errors/500.pl

# Rewrite Rules
RewriteEngine On

# Uncomment to turn on rewrite logging
# RewriteLog /var/log/koha/koha-opac-rewrite.log
# RewriteLogLevel 1
RewriteCond %{QUERY_STRING} (.*?)(?:[A-Za-z0-9_-]+)=&(.*)
RewriteRule (.+) $1?%1%2 [N,R,NE]

RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/opac-detail\.pl?bib=$1 [PT]
RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT]
RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT]
</VirtualHost>

## Intranet
<VirtualHost 173.193.109.146:8080>
ServerAdmin [email protected]
DocumentRoot /var/www/vhosts/openlx.com/koha/intranet/htdocs

<Directory /var/www/vhosts/openlx.com/koha/intranet/htdocs/>
php_admin_value open_basedir "/var/www/vhosts/openlx.com/koha/intranet/htdocs:/php/includes" </Directory>

## ServerName humanist.netshooter.com:8080
ServerName koha.openlx.com:8080
# ServerAlias intranet.mydomain.com
ScriptAlias /cgi-bin/koha/ "/var/www/vhosts/openlx.com/koha/intranet/cgi-bin/"
ScriptAlias /index.html "/var/www/vhosts/openlx.com/koha/intranet/cgi-bin/mainpage.pl"
ScriptAlias /search "/var/www/vhosts/openlx.com/koha/intranet/cgi-bin/search.pl"
ErrorLog /var/log/koha/koha-error_log
# TransferLog /var/log/koha/koha-access_log
SetEnv KOHA_CONF "/etc/koha/koha-conf.xml"
SetEnv PERL5LIB "/var/www/vhosts/openlx.com/koha/lib"
SetEnv MEMCACHED_SERVERS ""
SetEnv MEMCACHED_NAMESPACE ""
Options +FollowSymLinks

ErrorDocument 400 /cgi-bin/koha/errors/400.pl
ErrorDocument 401 /cgi-bin/koha/errors/401.pl
ErrorDocument 403 /cgi-bin/koha/errors/403.pl
ErrorDocument 404 /cgi-bin/koha/errors/404.pl
ErrorDocument 500 /cgi-bin/koha/errors/500.pl

<IfModule mod_gzip.c>
mod_gzip_on yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_can_negotiate yes
mod_gzip_update_static No
mod_gzip_temp_dir /tmp
mod_gzip_minimum_file_size 512
mod_gzip_maximum_file_size 1000000
mod_gzip_maximum_inmem_size 1000000
mod_gzip_handle_methods GET POST
mod_gzip_item_exclude reqheader "User-Agent: .*Mozilla/4\..*\["
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader Content-Type:image/*
mod_gzip_item_include file \.js$
mod_gzip_item_include mime ^application/javascript$
mod_gzip_item_include mime ^application/x-javascript$
mod_gzip_item_include file \.php$
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include file \.css$
mod_gzip_item_include mime ^text/css$
</IfModule>

<IfModule mod_deflate.c>

# Compress content with type html, text, and css, ...
AddOutputFilterByType DEFLATE text/plain text/html text/xml text/css
AddOutputFilterByType DEFLATE application/xml application/xhtml+xml application/rss+xml application/javascript application/x-javascript

DeflateCompressionLevel 9

# Properly handle old browsers that do not support compression
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio

LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
<IfModule mod_headers.c>
#properly handle requests coming from behind proxies
Header append Vary User-Agent
</IfModule>
</IfModule>

RewriteEngine On
# Uncomment to turn on rewrite logging
# RewriteLog /var/log/koha/koha-intranet-rewrite.log
# RewriteLogLevel 1

RewriteCond %{QUERY_STRING} (.*?)(?:[A-Za-z0-9_-]+)=&(.*)
RewriteRule (.+) $1?%1%2 [N,R,NE]
RewriteRule ^/bib/([^\/]*)/?$ /cgi-bin/koha/detail\.pl?bib=$1 [PT]
RewriteRule ^/isbn/([^\/]*)/?$ /search?q=isbn:$1 [PT]
RewriteRule ^/issn/([^\/]*)/?$ /search?q=issn:$1 [PT]
</VirtualHost>
 
more information

Hi SudhirG,
I read your post but I did not get what exactly is the problem. I guess, your subdomain koha.openlx.com is not showing up as it should be. I just visited it and it is showing the default apache page. Just to get this right:

a) you created a subdomain via plesk. means, it is showing up in you plesk account as subdomain, right? What did you mean with "but the domain does not get added". Added to what?

b) you were not saying anything about it but I guess you did restart your appache server after you copied the vhost.conf files? If not, you might just do this.

c) Does the koha application work with virtual domains? If not, I am surprised to see that it is actualy creating a httpd.conf file. My application usually use .htaccess files. Never had to work with vhost.conf for real subdomains.

d) when I create a subdomain via plesk on my server, a default page is automatically included. Would that be the case with your server, too? I am asking because the apache default page that I saw when accessing koha.openlx.com only showed up on my server when there was a conflict with the .htaccess/httpd.conf/vhost.conf files.

Regards,
Mike
 
Hello Mike,
Thanks for taking interest.

a. "but the domain does not get added" - I mean, that Kiha application does not show up on the domain. On a server withour plesk, after this step, Koha application starts becoming visible.
On my server, what you see as the default page is because of the sub-domain being added to Plesk. hat much is working because of lesk, fine.

b. Yes, I restarted apache and its restarting fine.

c. Koha does work with virtual domains. On my local server, which does not have Plesk, its working fine.

d. you are seeing a different default page because I removed the standard index.html file of plesk from the page. otherwise, as you will see now, that standard file is visible.

Is there a way through the .htaccess file ? Your help is greatly appreciated.
Or, do have to go away from Plesk ?

Thanks and best wishes,
Sudhir
 
ok, can see your new default page.
Question: I guess, this default page is found in the folder /var/www/olx.com/koha/, right?
But your vhosts.conf file is telling the server, that documen root is /var/www/olx.com/koha/opac/htdocs. So I guess, the vhosts.conf file get's ignored. You could check if the http.include file is doing any reference to your vhost.conf file.
Another option would be for you to add a .htaccess file to your /var/www/olx.com/koha folder
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ opac/htdocs/ [L]
RewriteRule (.*) opac/htdocs/$1 [L]
</IfModule>

at least, that works with me.
you can also add the vhost.conf file to the folder /etc/httpd/conf.d, renaming it to something like zkoha.conf.
then run /usr/local/psa/admin/sbin/websrvmng -a (via SSH comand line) and restarted the apache server.

That worked with my applications (virtual subdomains).
Unfortunately, I just try to find a way as I do not really know much about plesk or linux. so, be carefull when following my suggestions.
Good luck!
 
Same issue for me

Hi, I have installed Koha 3.8 on Debian 6+ running Plesk 11 as admin panel, and I have ran into same problem that installation has created virtual site for my Koha library application as

library.myuniversity.com

and I have created the subdomain in Plesk, I am lost to connect the the Apache created virtual domain with real subdomain in Plesk,

I created a .htaccess as more logical way to look into this but I get server error 500. Please help how I can overcome this issue.
 
Hi there,
for me, the solution above did not work. I did not manage to integrate virtual subdomains.

My config in httpd.include is:
<VirtualHost [my IP]>
ServerName wellness-heaven.net:80
ServerAlias www.wellness-heaven.net
....
</VirtualHost>

There seems to be a conflict with the deflate module:

<IfModule mod_gzip.c>
mod_gzip_on yes
mod_gzip_dechunk yes
mod_gzip_keep_workfiles No
mod_gzip_can_negotiate yes
mod_gzip_update_static No
mod_gzip_temp_dir /tmp
mod_gzip_minimum_file_size 512
mod_gzip_maximum_file_size 1000000
mod_gzip_maximum_inmem_size 1000000
mod_gzip_handle_methods GET POST
mod_gzip_item_exclude reqheader "User-Agent: .*Mozilla/4\..*\["
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader Content-Type:image/*
mod_gzip_item_include file \.js$
mod_gzip_item_include mime ^application/javascript$
mod_gzip_item_include mime ^application/x-javascript$
mod_gzip_item_include file \.php$
mod_gzip_item_include mime ^text/html$
mod_gzip_item_include file \.css$
mod_gzip_item_include mime ^text/css$
</IfModule>

Any ideas?
 
Back
Top