Author |
|
chrisiwien
Joined: 14 May 2024 Posts: 17 Location: Austria, Vienna
|
Posted: Sat 18 May '24 22:37 Post subject: VHost of domain redirected to server isn't recognized |
|
|
For testing purposes i created a VHost with following contents (in my httpd-vhosts.conf are several vhosts defined):
Code: | <VirtualHost *:80>
ServerName test.testserver.info
DocumentRoot "${SRVROOT}/htdocs/files/"
<Directory "${SRVROOT}/htdocs/files/">
Require all granted
AllowOverride All
</Directory>
</VirtualHost> |
Also, there is a VHost for test.testserver.info:443 present.
------------------------------------------------
FIRST PROBLEM:
Now, the productive domain, eg. shop.domain.com, shall also point to ${SRVROOT}/htdocs/files/ - and this doesn't work.
I set up a new virtual host:
Code: | <VirtualHost *:80>
ServerName shop.domain.com
DocumentRoot "${SRVROOT}/htdocs/files/"
<Directory "${SRVROOT}/htdocs/files/">
Require all granted
AllowOverride All
</Directory>
</VirtualHost> |
and this doesn't work, i am always redirected to the first vhost in httpd-vhosts.conf.
------------------------------------------------
SECOND PROBLEM:
And this is also not right, because if a domain is not known in httpd-vhosts.conf (via ServerName), the main server page should be called, which i defined in httpd.conf as follows:
Code: | ServerName www.serverurl.com:80
DocumentRoot "${SRVROOT}/htdocs/"
<Directory "${SRVROOT}/htdocs/">
AllowOverride none
Require all denied
</Directory> |
But i am always redirected to the first VHost in httpd-vhosts.conf.
The DNS entries for "shop.domain.com" are already made, today afternoon, and "shop.domain.com" points correctly to my server IP.
Whats wrong? With the test domain "test.testserver.info" it worked without any problems, with "shop.domain.com" is doesn't work. |
|
Back to top |
|
mrdj1024
Joined: 03 Apr 2023 Posts: 38 Location: Bridgeton,NJ,USA
|
Posted: Sun 19 May '24 1:02 Post subject: |
|
|
you might need to add a CNAME record for the redirection to work properly,you could sign into your DNS record control panel and add the record and try again. |
|
Back to top |
|
chrisiwien
Joined: 14 May 2024 Posts: 17 Location: Austria, Vienna
|
Posted: Sun 19 May '24 3:01 Post subject: |
|
|
Thanks for your reply.
DNS entries: But why this is different? For the domain in my post "test.testserver.info" i only have do define an A record and it works.
I created for testing purposes another test domain with the hoster where i have created "test.testserver.info" - an it worked without any problems. So you are probably right, with the cname entry.
Log in to your panel... haha... usually, i am doing this, of course. In the case of "shop.domain.com" i have to talk to an administrator, who himself have to open a support ticket at the domain hosting company. Just a little communication nightmare... |
|
Back to top |
|
mrdj1024
Joined: 03 Apr 2023 Posts: 38 Location: Bridgeton,NJ,USA
|
Posted: Sun 19 May '24 12:57 Post subject: |
|
|
yeah sometimes a CNAME record is needed,i know www. don't work without a www CNAME record pointing to the actual domain
like www.yoursite.com dont work unless you CNAME
www(for the CNAME) then yoursite.com as the actual site name
then it works just fine |
|
Back to top |
|
chrisiwien
Joined: 14 May 2024 Posts: 17 Location: Austria, Vienna
|
Posted: Sun 19 May '24 14:57 Post subject: |
|
|
Update: the „support“ team of the domain hoster has made an http redirect to the server ip, not a change in the DNS entries.
I am getting somehow frustrated now… ![Neutral](images/smiles/icon_neutral.gif) |
|
Back to top |
|
mrdj1024
Joined: 03 Apr 2023 Posts: 38 Location: Bridgeton,NJ,USA
|
Posted: Sun 19 May '24 15:44 Post subject: |
|
|
a redirect isn't what you need
ask them for a CNAME record to be made,but if you have a free subdomain or have an actual domain name,you should be able to log in and add your records,i don't know why you dont have access to your record management system.
check these guys out they are great and are free for subdomains if you need one for a website
https://www.dynu.com/en-US/ |
|
Back to top |
|
chrisiwien
Joined: 14 May 2024 Posts: 17 Location: Austria, Vienna
|
Posted: Sun 19 May '24 16:04 Post subject: |
|
|
Of course, a http redirect is completely nonsense in this case.
But now the admin managed to change the DNS entry. Guess it will work now without CNAME, will see.
Btw., this hoster isn‘t free, but a large Austrian Internet company. |
|
Back to top |
|
Stray78
![](images/avatars/1138666473398adc46.jpg)
Joined: 15 Apr 2024 Posts: 22 Location: USA
|
Posted: Mon 20 May '24 3:53 Post subject: |
|
|
Do you have a DNS A record? i have one for mydomain.com & *.mydomain.com. The wild card sends all subdomains to my server IP. |
|
Back to top |
|
chrisiwien
Joined: 14 May 2024 Posts: 17 Location: Austria, Vienna
|
Posted: Mon 20 May '24 12:52 Post subject: |
|
|
Yes, NOW there is an A record. Problem was the URL redirection, that doesn‘t work.
Now with shop.domain.com A xxx.xxx.xxx.xxx everything works fine. |
|
Back to top |
|
chrisiwien
Joined: 14 May 2024 Posts: 17 Location: Austria, Vienna
|
Posted: Mon 20 May '24 12:57 Post subject: |
|
|
Perhaps you have also an answer to my second problem, i wrote about in my initial post: not the server main page is called, if a domain points to my server and no vhost for that domain is defined, but the first vhost in the httpd-vhosts.conf.
I don‘t know what’s wrong in my configuration. |
|
Back to top |
|
Stray78
![](images/avatars/1138666473398adc46.jpg)
Joined: 15 Apr 2024 Posts: 22 Location: USA
|
Posted: Tue 21 May '24 12:21 Post subject: Re: VHost of domain redirected to server isn't recognized |
|
|
chrisiwien wrote: | ------------------------------------------------
SECOND PROBLEM:
And this is also not right, because if a domain is not known in httpd-vhosts.conf (via ServerName), the main server page should be called, which i defined in httpd.conf as follows:
Code: | ServerName www.serverurl.com:80
DocumentRoot "${SRVROOT}/htdocs/"
<Directory "${SRVROOT}/htdocs/">
AllowOverride none
Require all denied
</Directory> |
But i am always redirected to the first VHost in httpd-vhosts.conf. |
That is only a partial config to see, but is this the vhost section or directory? You have things that don't need to be in there if it is a directory section.
And nobody will get to that web page because access is denied (Require all denied). You need something like this.
*** Directory Section ***
<Directory "${SRVROOT}/htdocs/">
Options FollowSymLinks
AllowOverride None
<LimitExcept HEAD GET POST>
Require all denied
</LimitExcept>
Require all granted
</Directory>
*** Vhost Section ***
#
<VirtualHost *>
# Server Stuff #
ServerName serverurl.com
ServerAlias www.serverurl.com
DocumentRoot "${SRVROOT}/htdocs/"
</VirtualHost>
#
*** EDIT: *** I see now you have the directory section inside the vhost. Never seen that before. I keep my directory sections in my httpd.conf & vhost section in the httpd-vhost.conf.
I would remove the port in the ServerName Directive, and you need "Require all granted" if you want people to reach that website. |
|
Back to top |
|
chrisiwien
Joined: 14 May 2024 Posts: 17 Location: Austria, Vienna
|
Posted: Tue 21 May '24 12:55 Post subject: |
|
|
Hey Stray78,
thanks for your answer.
Hm, putting the <Directory> section into the vHost declaration seems to me very logic... because the directory belongs to this vHost. It seems to work and, Apache doesn't throw any error if i restart the webserver. Is that still wrong or faulty?
Requier all denied... means not the vHost or main server page is not reachable. It means, that the user will see a 403 Forbidden message - wich is ok for me for the main server page. Eg. if you you call www.serverurl.com directly, you see a 403 Forbidden, so, if someone calls an URL pointing to my server, but which is unknown in httpd-vhosts.conf, this 403 page should be also presented.
But I will try your proposal.
In your answer you define an extra vHost for the main server page - this is new for me. And this has to be done? I thought, the main server page is reachable without any vHost declaration.
The section
Code: | ServerName www.serverurl.com:80
DocumentRoot "${SRVROOT}/htdocs/"
<Directory "${SRVROOT}/htdocs/">
AllowOverride none
Require all denied
</Directory> |
is defined without a vHost declariation in httpd.conf.
--------------------------------------------------------
My vHost declarations (NOT the main server page) looks like this:
Code: | <VirtualHost *:80>
ServerName shop.domain.com
ServerAdmin mail@shopdomain.com
DocumentRoot "${SRVROOT}/htdocs/shopfiles/"
<Directory "${SRVROOT}/htdocs/shopfiles/">
Require all granted
AllowOverride All
</Directory>
Redirect permanent / https://shop.domain.com/
</VirtualHost> |
Code: |
<VirtualHost *:443>
ServerName shop.domain.com
ServerAdmin mail@shopdomain.com
SSLEngine On
SSLProtocol -ALL +TLSv1 +TLSv1.2
Protocols h2 http/1.1
SSLCompression Off
SSLSessionTickets on
SSLHonorCipherOrder off
SSLCipherSuite ECDH+AESGCM:ECDH+AES256:!aNULL:!MD5:!DSS:!DH:!AES128
SSLVerifyDepth 10
SSLCertificateFile "c:/Apache24/conf/certs/shop.domain.com-crt.pem"
SSLCertificateKeyFile "c:/Apache24/conf/certs/shop.domain.com-key.pem"
SSLCertificateChainFile "c:/Apache24/conf/certs/shop.domain.com-chain.pem"
DocumentRoot "${SRVROOT}/htdocs/shopfiles/"
SetEnv OPCACHE_ID "shop"
<Directory "${SRVROOT}/htdocs/shopfiles/">
Require all granted
AllowOverride All
Options +ExecCGI
<Files ~ "\.php$">
AddHandler fcgid-script .php
FcgidWrapper 'C:/phpnts/php-cgi.exe' .php
</Files>
</Directory>
<IfModule evasive_module>
DOSBlockingPeriod 0
</IfModule>
LogLevel info ssl:warn
ErrorLog "logs/shop.domain.com.error.log"
CustomLog "logs/shop.domain.com.info.log" common
</VirtualHost> |
----------------------------------------------
I don't know if the declarations
Code: | AddHandler fcgid-script .php
FcgidWrapper 'C:/phpnts/php-cgi.exe' .php |
are completely right, but, according to the error/message log, they do what they should: if any vHost is called (via the URL), a fcgid-process is generated for this vHost. |
|
Back to top |
|
Stray78
![](images/avatars/1138666473398adc46.jpg)
Joined: 15 Apr 2024 Posts: 22 Location: USA
|
Posted: Tue 21 May '24 18:01 Post subject: |
|
|
Yes it does make sense to put the directory section inside the vhost, I just never seen it done that way. I just kept it how the original config files were. If it works that's all that matters.
You are correct, Require all denied would end in a 403.
You do not have to create a vhost for the main webroot "htdocs". It was just an example.
And I have no clue about the fcgid stuff, I always have ran a thread safe module.
So here is your fix for going to wrong vhost...
So your vhost section looks fine. Mine did weird stuff too. If you type in the wrong subdomain it will send you to the first vhost. Not sure why it does that.
This works for me. In your vhost section use a wildcard ServerAlias directive.
Code: |
<VirtualHost *>
# Server Stuff #
ServerName mydomain.com
ServerAlias *.mydomain.com
DocumentRoot "${WEBROOT}/www/"
...
</VirtualHost>
|
But if you have subdomains like shop.mydomain.com, make sure that is higher in the vhost file than the wildcards or it will not work.
Code: | <VirtualHost *>
# Server Stuff #
ServerName shop.mydomain.com
DocumentRoot "${WEBROOT}/www/shop"
...
</VirtualHost>
<VirtualHost *>
# Server Stuff #
ServerName mydomain.com
ServerAlias *.mydomain.com
DocumentRoot "${WEBROOT}/www/"
...
</VirtualHost>
|
|
|
Back to top |
|