Name based virtual hosts serve the same SSL site - ssl

On my server I have the following vhost definition:
<VirtualHost *:80 *:443>
ServerAdmin admin#mysiste.com
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot /var/www/mysite.com/current/public
SSLEngine on
SSLCertificateKeyFile /etc/ssl/ssl.key/myserver.key
SSLCertificateFile /etc/ssl/ssl.crt/mysite_com.crt
SSLCertificateChainFile /etc/ssl/ssl.crt/mysite_com.ca-bundle
<Directory /var/www/mysite.com/current/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
The site itself works fine, the problem is that if I try any other site (vhost) hosted on the same server with https and skip the warning I get served mysite.com. This wouldn't be a problem for the casual user but I noticed Google tried and actually indexed a ton of URLs on my "other" sites via https which were actually pages from mysite.com and I'm afraid I'll get penalized for duplicate content.
How do I deny the other sites to be served via https?

I solved the issue. For further reference this is Ubuntu 12.04.
In /etc/apache2/ports.conf added the following to the <IfModule mod_ssl.c> section:
NameVirtualHost *:443
As per the instructions in the above file, modified in /etc/apache2/sites-available/default-ssl from <VirtualHost _default_:443> to <VirtualHost *:443>.
Then:
sudo a2ensite default-ssl
sudo service apache2 reload
Done.

Related

Apache conf VirtualHost ignored

I'm running apache on a CentOS 7.
I have 2 config files in /etc/httpd/conf.d :
A10-my_site_dev.conf
A10-my_site_test.conf
As they are similar, I show you only one of the files :
<VirtualHost *:443>
ErrorLog "logs/my_site_test.log"
SSLCertificateFile /etc/ssl/host/host.crt
SSLCertificateKeyFile /etc/ssl/host/host.key
Alias /my-site/test/static /var/www/my_site_test/static/
<Directory /var/www/my_site_test/static>
Require all granted
</Directory>
WSGIScriptAlias /my-site/test /var/www/my_site_test/app/wsgi.py
<Directory /var/www/my_site_test>
Require all granted
</Directory>
</VirtualHost>
Currently, VirtualHost in A10-my_site_test.conf is ignored. If I go to https://my-server.com/my-site/test, I've got a 404, but https://my-server.com/my-site/dev is working fine.
If I remove A10-my_site_dev.conf and restart apache, https://my-server.com/my-site/test works.
I understood that it takes only the first VirtualHost apache finds.
I have the feeling that VirtualHost in my ssl.conf is ignored too cause, if I move SSLCertificateFile and SSLCertificateKeyFile to ssl.conf, I have the following error :
I tried not to use VirtualHost, and everything works fine in that case. I think all VirtualHost are ignored except the first.
I've got the same problem with other ports (like 80).
Another point : I read that I should have a ServerName. But I have the same ServerName for all my environments. I tried to put something random such as "my_site_test" as ServerName, but I've got a 404.
How could I configure apache to make my 2 files work ?
This is not how VirtualHosts work. Especially with SSL.
So you have:
<VirtualHost *:443>
CONFIGURATION FOR DEV
</VirtualHost>
<VirtualHost *:443>
CONFIGURATION FOR TEST
</VirtualHost>
The only difference between both VirtualHosts is the logs and directory? That will not work.
Apache can distinguish between VirtualHost sections based on:
IP associated to the domain
Port
ServerName (for non-SSL configurations)
The way you configured it right now, Apache cannot distinguish between both VirtualHosts. So it takes the first one it finds. That explains the mix up with certificates.
Ex of a working configuration
# www.example1.com == 1.1.1.1
# www.example2.com == 2.2.2.2
<VirtualHost 1.1.1.1:443>
ServerName www.example1.com
# SSL CONFIG
# LOGS CONFIG
# OTHER CONFIGURATION
</VirtualHost>
<VirtualHost 2.2.2.2:443>
ServerName www.example2.com
# SSL CONFIG
# LOGS CONFIG
# OTHER CONFIGURATION
</VirtualHost>
Read the documentation (again?), it will do you good: https://httpd.apache.org/docs/2.4/vhosts/examples.html
There are posts on this site explaining the finer points of SSL VirtualHosts configuration (I even wrote some myself).

Apache disable localhost redirection

i got a problem with apache conf with Laragon.
so the case is :
i got 2 subdomain
subdom1.mysite.com (DNS Record to IP 1.2.3.4)
subdom2.mysite.com (DNS Record to IP 1.2.3.4)
IP 1.2.3.4 is my VPS
everything went well, but i got a problem.
when i access 'localhost' from my VPS, it keeps redirecting to subdom1.mysite.com
and localhost/phpMyAdmin also redirected to subdom1.mysite.com/phpMyAdmin
here's my httpd.conf
Define APACHE_LOG_DIR "C:/mydir/logs"
Define APACHE_ROOT_WEB_DIR "C:/mydir/wwwroot"
ServerName localhost
DocumentRoot "C:/mydir/wwwroot"
<Directory "C:/mydir/wwwroot">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<VirtualHost *:80>
ServerName subdom1.mysite.com
ServerAlias subdom1.mysite.com
DocumentRoot ${APACHE_ROOT_WEB_DIR}\subdom1.mysite.com
ErrorLog ${APACHE_LOG_DIR}/subdom1.mysite.com-error.log
CustomLog ${APACHE_LOG_DIR}/subdom1.mysite.com-access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName subdom2.mysite.com
ServerAlias subdom2.mysite.com
DocumentRoot ${APACHE_ROOT_WEB_DIR}\subdom2.mysite.com
ErrorLog ${APACHE_LOG_DIR}/subdom2.mysite.com-error.log
CustomLog ${APACHE_LOG_DIR}/subdom2.mysite.com-access.log combined
</VirtualHost>
my localhost keeps redirecting to first vHost. I've googled lot's of combination of directory, serverName etc. But no luck.
Your VirtualHosts are binding to all available interfaces. Because of how apache determines to which VHost should route a request, it's ending up in the first one defined.
You can either:
Bind your subdomains to the external ip only.
Create a VirtualHost for the main server using the loopback ip.
Create a VirtualHost with the _default_ address.

running website with no http show different content

Im running 3 sites in one server the same IP in Ubuntu/Apache using vhost.
I bought an SSL certificate and installed it in one of my sites successfully. The problem is when I run the site with no https it shows content from my other site.
Ex.
www.aaaaa.com
www.bbbbb.com (SSL)
www.ccccc.com
when I run https://bbbbb.com there is no problem but
when I run http://bbbbb.com it shows the content of www.aaaaa.com
I know the ssl is working correctly coz I have tested it sslchecker.
This is the first time I installed SSL, I hope someone knows something about this problem.
ok just got the Answer from this link
https://www.namecheap.com/support/knowledgebase/article.aspx/9821/38/redirect-to-https-on-apache
You just need to Redirect HTTPS on Apache. Solution is I added vhost port 80 on my conf file in apache to redirect it to https when accessing the site with no https.
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#example.com
ServerName example.com.ca
ServerAlias www.example.com
DocumentRoot /var/www/example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/example.com/example.ca.crt
SSLCertificateKeyFile /etc/ssl/example.com/example.key
SSLCertificateChainFile /etc/ssl/example.com/example.ca.ca-bundle
</VirtualHost>

Apache: using vhosts

I've added a new entry to vhosts, d3test. When I go to d3test/ in Google Chrome, the page isn't found, Oops! Google Chrome could not find d3test.
All of my other entries work fine, for example graphgram/ shows the correct site.
Here is my vhosts:
#
# Use name-based virtual hosting.
#
NameVirtualHost 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
DocumentRoot /Users/donald/Projects/graphgram
ServerName graphgram
</VirtualHost>
<VirtualHost 127.0.0.1:80>
DocumentRoot /Users/donald/Projects/lookgram
ServerName lookgram
</VirtualHost>
<VirtualHost 127.0.0.1:80>
DocumentRoot /Users/donald/Projects/d3test
ServerName d3test
</VirtualHost>
Why would all entries work except the last one?
have you added that entry to /etc/hosts aswell? just in case make sure. And restart your service after that.. should work, check what the log says...

Apache Multiply Sites again

OK. I have LAMP server on my local development machine. I need to develop few sites on it. So, I've created two files (configs of my sites) in $APACHE/sites-available and made symlinks for them for /sites-enabled. After that I've started sudo /etc/init.d/apache2 restart. No errors or warnings. When I try mysite.dev it gives it, and when foobar.dev - it gives mysite.dev!
So, apache gives one site for all virtual hosts. How to fix it?
http://pastebin.com/qjcx6RS3 (first site)
http://pastebin.com/FdVStJm8 (second site)
You'll need to set NameVirtualHost-directive like this in your httpd.conf:
NameVirtualHost *:80
Example with two vhosts (like in your case):
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.domain.tld
ServerAlias domain.tld *.domain.tld
DocumentRoot /www/domain
</VirtualHost>
<VirtualHost *:80>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
... it would of course also be possible to include the vhosts from seperate files into the httpd.conf.