Question

Apache2 - Vhost keep redirect to https vhost, and not the request vhost

  • Posted October 10, 2013

i am facing an issue with my vHost setup which I rly can’t figure out how to fix

First my vhost config:

<VirtualHost *:80>
ServerName dnsmaster.*****.com:80
DocumentRoot /var/www/dns
<Directory />
	Options FollowSymLinks
	AllowOverride None
</Directory>
<Directory /var/www/dns>
	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>
<VirtualHost *:443>
ServerName chat.*****.com:443
DocumentRoot /var/www/chat
<Directory />
	Options FollowSymLinks
	AllowOverride None
</Directory>
<Directory /var/www/chat>
	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
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
</VirtualHost>

Both vHost are located in the default file (000-default)

  • Also this is all there is in that file.

The first vHost works fine, and are also working with SSL/HTTPS but when I try to go to second vHost, then it redirects me to the first one.

I’ve never faced this problem before, and have been setting a few vHosts up in the past.

But never 2 vHost where one is HTTPS and the other is HTTP

also this is the ports.conf: (default)

NameVirtualHost *:80
Listen 80

<IfModule mod_ssl.c>
NameVirtualHost *:443
Listen 443
</IfModule>

<IfModule mod_gnutls.c>
Listen 443
</IfModule>
Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi, <br> <br>Did you get this resolved? I am having the same problem and was wondering how you got it to work <br>For me <br>- http://www.site1.com works (site1.conf) <br>- https://www.site2.com works (default-ssl conf) <br>- http://www.site3.com works (site2.conf) <br>BUT <br>- http:///www.site4.com redirects to https://www.site2.com (site3.conf) <br> <br>I cant figure out what the difference is between site3.conf and site2.conf - other than document root… <br> <br>No help in the log files - have rebooted - <br> <br> <br> <br>

drwxr-xr-x 4 root root 4096 Oct 12 14:59 . <br>drwxr-xr-x 12 root root 4096 Oct 10 14:59 … <br>drwxr-xr-x 10 root root 4096 Oct 11 15:46 chat <br>drwxr-xr-x 7 root root 4096 Oct 10 17:10 dns <br>-rw-r–r-- 1 root root 7 Oct 12 11:06 index.php <br>

What’s the output of <code>ls -la /var/www/</code>?

No, when I go to http://dnsmaster., I get redirected to https.chat.. that’s the problem

<pre>If I go to #4 https://dnsmaster..com - the URL is then still https://dnsmaster..com, but still goes to chat..com site</pre> <br> <br>That is expected since the only virtualhost listening on 443 is chat. so you cannot prevent that unless you move it to a separate droplet. <br> <br>Does http://dnsmaster.** work normally?

forgot: <br> <br>If I go to #4 https://dnsmaster..com - the URL is then still https://dnsmaster..com, but still goes to chat.****.com site

Hello Kamal, <br> <br>All 4 goes to https//chat.****.com

What happens when you visit: <br> <br><ol><li>http://chat..com</li><li>https://chat..com</li><li>http://dnsmaster..com</li><li>https://dnsmaster..com</li></ol>

Because that doesn’t work either :/

Why not separate the two vHosts, instead of having them in the same <code>000-default</code> file?