What's wrong with this simple SSL Vhost declaration? - apache

Any reason why the middle vhost setting is causing an issue w/ Apache? Maybe it's because I don't have the SSL details in there?
<VirtualHost *:80>
ServerName www.windfarmstudios.com
ServerAlias windfarmstudios.com
Redirect permanent / https://windfarmstudios.com
</VirtualHost>
#<VirtualHost *:443>
# ServerName www.windfarmstudios.com
# Redirect permanent / https://windfarmstudios.com
#</VirtualHost>
<VirtualHost *:443>
ServerName windfarmstudios.com
DocumentRoot /var/www/windfarmstudios.com/public_html
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/windfarm.crt
SSLCertificateKeyFile /etc/apache2/ssl/windfarm.key
SSLCACertificateFile /etc/apache2/ssl/windfarm.ca-bundle
</VirtualHost>

Related

httpd VirtualHost overwrite another VirtualHost

I have a problem whereby my VirtualHost is overriding another VirtualHost on the same domain.
httpd.conf
IncludeOptional conf.d/*.conf
example.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/example/
ServerName www.example.com
ServerAlias www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/html/example/
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/example/example.crt
SSLCertificateKeyFile /etc/httpd/ssl/example/example.key
SSLCertificateChainFile /etc/httpd/ssl/example/chain.cer
ServerName www.example.com
ServerAlias www.example.com
</VirtualHost>
get.example.conf
<VirtualHost *:80>
DocumentRoot /var/www/html/get.example/
ServerName get.example.com
ServerAlias get.example.com
</VirtualHost>
When I created get.example.conf and when I accessed example.com, it is showing the content of get.example.com
Does anyone knows what is going wrong with my configuration?
Found out that I need to include the non-www for the VirtualHost as well. It works if I entered www.example.com but not example.com.
<VirtualHost *:80>
ServerName example.com
Redirect permanent / http://www.example.com/
</VirtualHost>
You just have to set up de ServerAlias.
In your example, it should be enough to do as follow:
<VirtualHost *:80>
DocumentRoot /var/www/html/example/
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://www.example.com/
</VirtualHost>
Note that ServerName doesn't has www., so that it's gonna match http://example.com, while with the ServerAlias it's gonna match http://www.example.com
Try to change the order of ServerName and ServerAlias to your get.example.conf:
<VirtualHost *:80>
ServerName get.example.com
ServerAlias get.example.com
DocumentRoot /var/www/html/get.example/
</VirtualHost>

Apache22: how to redirect a dir to https?

Say, I have a domain http://www.example.com. I have this in httpd.conf: DocumentRoot "/Apache22/htdocs".
I also have /Apache22/htdocs/dir1 application directory, which I want to force users to connect to with https, say, with URL: https://www.example.com/dir1 and redirect any http requests to https for this directory.
I tried VirtualHost and Redirect so:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /Apache22/htdocs/
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com/dir1
DocumentRoot /Apache22/htdocs/dir1
Redirect permanent /dir1 https://www.example.com/dir1
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
ServerName www.example.com/dir1
DocumentRoot /Apache22/htdocs/dir1
SSLEngine on
SSLCertificateFile conf/ssl/server.cert
SSLCertificateKeyFile conf/ssl/server.key
</VirtualHost>
But apparently Apache ignores any subdrectories in ServerName, so both www.example.com and www.example.com/dir1 are the same in VirtualHost block, as far as Apache concerned.
How do I achieve an https redirect of any URL accessing dir1?
Try:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /Apache22/htdocs/
Redirect permanent /dir1 https://www.example.com/dir1
</VirtualHost>
NameVirtualHost *:443
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot /Apache22/htdocs
SSLEngine on
SSLCertificateFile conf/ssl/server.cert
SSLCertificateKeyFile conf/ssl/server.key
</VirtualHost>
The ServerName directive takes a host name, not anything including a path component.

VirtualHost: Deactivate catch all for SSL (443)

I created a SSL VirtualHost
<VirtualHost *:443>
ServerName cloud.url.com
ServerAlias www.url.com
DocumentRoot /var/www/owncloud
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/owncloud.crt
SSLCertificateKeyFile /etc/apache2/ssl/owncloud.key
</VirtualHost>
My problem is that every SSL connection now is going to /var/www/owncloud
For instance https://url.com is going to /var/www/owncloud instead of /var/www/
How can I only set the VirtualHost for cloud.url.com and the other domains "ignore the ssl" - so they stay in there directories?
In fact, your virtualhost says www.url.com and cloud.url.com goes to /var/www/owncloud. I think you don't want www.url.go to points to your owncloud. So, just remove serverAlias :
<VirtualHost *:443>
ServerName cloud.url.com
DocumentRoot /var/www/owncloud
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/owncloud.crt
SSLCertificateKeyFile /etc/apache2/ssl/owncloud.key
</VirtualHost>
I think you haven't set any virtualhost listening to url.com on port 443. That's why, apache redirect it to an url configured with https.
if you don't want ssl on url.com, you can just do this :
<VirtualHost *:443>
ServerName url.com
Redirect 301 / http://url.com
</VirtualHost>
Found the solution, put this in one file together:
<VirtualHost *:443>
ServerName cloud.domain.com
ServerAlias www.cloud.domain.com
DocumentRoot /var/www/owncloud
<Directory /var/www/owncloud/>
Options -Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/owncloud.crt
SSLCertificateKeyFile /etc/apache2/ssl/owncloud.key
</VirtualHost>
<VirtualHost *:443>
ServerName domain.com
ServerAlias *.domain.com
Redirect 301 / http://domain.com
</VirtualHost>
Thank you!

Wildcard SSL setup. Invalid domain error message

I am trying to setup a wildcard SSL (working on all subdomains). Both domains work fine: domain.com and www.domain.com. However, when I go to https://test.domain.com I get an invalid SSL/domain error message in my browser. Any idea how I can fix this?
Here is my virtual host settings. I am on Ubuntu/Apache2.
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/*.domain.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/*.domain.com.key
SSLCACertificateFile /etc/apache2/ssl/*.domain.com.bundle.crt
ServerName domain.com
ServerAlias domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/domain.com/public_html/
ErrorLog /var/www/domain.com/logs/error.log
</VirtualHost>
<VirtualHost *:80>
ServerName domain.com
ServerAlias domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/domain.com/public_html/
ErrorLog /var/www/domain.com/logs/error.log
</VirtualHost>
Found the issue! I had to purchase a wildcard SSL. Duh!

Apache - Proxy all subdomains from one IP

I'm trying to handle subdomains on a specific server and the normal URL from all servers. They're behind a load balancer. This works for http://test.com and it load balances.
For subdomains I can't tell if the proxy is working or why I'm getting a 404 error. Is there anything wrong with my config?
DNS: example.com 111.111.111.111
Load Balancer: 111.111.111.111
Master, write server: 222.222.222.222
httpd.conf, mirrored to all servers:
<Directory />
Header add myServerName "anglefish" # add a string for testing which server
Header add myServerTimes "D%D t%t"
</Directory>
000-default mirrored to each server except master
#Proxy subdomains from one server
<VirtualHost *:80>
ServerName *.example.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://222.222.222.222/
ProxyPassReverse / http://222.222.222.222/
</VirtualHost>
<VirtualHost *:443>
ServerName *.example.com
SSLEngine on
SSLProxyEngine On
SSLEngine on
SSLCertificateFile /etc/apache2/.ssh/example.com.crt
SSLCertificateKeyFile /etc/apache2/.ssh/example.com.key
SSLCertificateChainFile /etc/apache2/.ssh/example.com_bundle.crt
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://222.222.222.222/
ProxyPassReverse / http://222.222.222.222/
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/vhosts/example.com/public_html
<Directory /var/www/vhosts/example.com/public_html>
Options -Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias example.com
DocumentRoot /var/www/vhosts/example.com/public_html
SSLEngine on
SSLCertificateFile /etc/apache2/.ssh/example.com.crt
SSLCertificateKeyFile /etc/apache2/.ssh/example.com.key
SSLCertificateChainFile /etc/apache2/.ssh/example.com_bundle.crt
</VirtualHost>