Apache redirect 443 timeout error - apache

My redirection from 80 to 443 port doesn't work.
I have an error timeout
here is my conf file :
<VirtualHost *:80>
ServerName www.example.com
Redirect "/" "https://www.example.com/"
</VirtualHost>
<VirtualHost *:443>
ServerName www.example.com
DocumentRoot "C:/Myfolder"
<Directory "C:/Myfolder">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
DirectoryIndex home.html
</Directory>
SSLEngine on
SSLCertificateFile conf/ssl/certs/wildcard.mydomain.com.crt
SSLCertificateKeyFile conf/ssl/private/wildcard.mydomain.com.key
SSLCertificateChainFile conf/ssl/certs/wildcard.mydomain.com.pem
SSLVerifyClient None
Alias ...
</VirtualHost>
But Everything is working ok if I replace
<VirtualHost *:80>
with
<VirtualHost www.example.com:80>
and
<VirtualHost *:443>
with
<VirtualHost www.example.com:443>
Any idea please ? Thank you.

Related

Apache 2.4 too many redirects with www to non-www and http to https

httpd.conf:
Include conf.d/ports.conf
IncludeOptional sites-enabled/*.conf
conf.d/ports.conf
Listen 80
Listen 443
sites-enabled/example.com.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
SSLEngine on
SSLCertificateFile /etc/httpd/ssl/example.com.certificate.pem
SSLCertificateKeyFile /etc/httpd/ssl/example.com.key.key
<Directory /var/www/example.com/public_html/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/httpd/example.com.error.log
CustomLog /var/log/httpd/example.com.access.log combined
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/example.com/public_html/$1
DirectoryIndex index.php index.html
</VirtualHost>
... but it just gives me "too many redirects" for any combination (www, non-www, http or https).

Adding second domain to LAMP stack

I currently have one domain set up on my LAMP server, and I want to add another one. I tried doing it myself but when I ran into issues, I follow this. I had example.com set up and it was working fine, all traffic would redirect to its https and I want to continue that.
However, the second domain I'm using (represented by test.ca) is still going to example.com. I was hoping someone could inform me what I am doing wrong. Should test.ca be a folder within example.com? and how do you point to it? Is it cause I redirect traffic to https://example.com for the ssl so all traffic just goes there?
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:80>
ServerName test.ca
Redirect permanent / http://test.ca
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/ssl/localcerts/example.com.crt
SSLCertificateKeyFile /etc/ssl/localcerts/example.com.key
SSLCACertificateFile /etc/ssl/localcerts/intermediate.crt
ServerAdmin example#gmail.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example.com/public_html/
ErrorLog /var/www/html/example.com/logs/error.log
CustomLog /var/www/html/example.com/logs/access.log combined
<Directory /var/www/html/example.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerAdmin example#gmail.com
ServerName test.ca
ServerAlias www.test.ca
DocumentRoot /var/www/html/test.ca/public_html/
ErrorLog /var/www/html/test.ca/logs/error.log
CustomLog /var/www/html/test.ca/logs/access.log combined
<Directory /var/www/html/test.ca/>
Require all granted
</Directory>
</VirtualHost>
/etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/ssl/localcerts/example.com.crt
SSLCertificateKeyFile /etc/ssl/localcerts/example.com.key
SSLCACertificateFile /etc/ssl/localcerts/intermediate.crt
ServerAdmin example#gmail.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/example.com/public_html/
ErrorLog /var/www/html/example.com/logs/error.log
CustomLog /var/www/html/example.com/logs/access.log combined
<Directory /var/www/html/example.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
/etc/apache2/sites-available/test.ca.conf
<VirtualHost *:80>
ServerName test.ca
Redirect permanent / http://test.ca
</VirtualHost>
<VirtualHost *:444>
ServerAdmin example#gmail.com
ServerName test.ca
ServerAlias www.test.ca
DocumentRoot /var/www/html/test.ca/public_html/
ErrorLog /var/www/html/test.ca/logs/error.log
CustomLog /var/www/html/test.ca/logs/access.log combined
<Directory /var/www/html/test.ca/>
Require all granted
</Directory>
</VirtualHost>
You might want to change the header of the Virtualhost from
<VirtualHost *:444>
to
<VirtualHost *:443>
as a start, or it must be your intentions to link to that port instead of the default https port.

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!

Adding SSL to my website

I have the following virtual hosts config:
listen 80
listen 443
servername "example.com"
serveradmin "email#example.com"
namevirtualhost *:80
namevirtualhost *:443
directoryindex index.html index.php
options -indexes -multiviews +followsymlinks
<directory /Volumes/dev1/http>
allowoverride all
</directory>
<virtualhost *:80 *:443>
servername example.com
serveralias www.example.com
documentroot "/Volumes/dev1/http/example"
rewriteengine on
SSLCertificateFile "/Volumes/dev1/ssl/_ssl-cert.crt"
SSLCertificateKeyFile "/Volumes/dev1/ssl/_ssl-privatekey.crt"
SSLCertificateChainFile "/Volumes/dev1/ssl/_ssl-csr.crt"
</virtualhost>
Of course example.com is just an ... example.
All is well if I access http://example.com, but if I try to access the HTTPS version I get
Safari can’t open the page “https://example.com/” because Safari
can’t establish a secure connection to the server “example.com”.
The _ssl* files are all in place and running httpd -t from Terminal returns Syntax OK.
What am I doing wrong? Thanks!
This what I'm using (only the vhosts section), omitting the FCGID, suexec and PHP specific parts:
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/var/www/example.com/htdocs"
<Directory "/var/www/example.com/htdocs/">
Options -Indexes
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog "/var/www/example.com/error.log"
CustomLog "/var/www/example.com/access.log" combined
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
DocumentRoot "/var/www/example.com/htdocs"
<Directory "/var/www/example.com/htdocs/">
Options -Indexes
AllowOverride All
Order allow,deny
Allow from All
</Directory>
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/apache/ssl/example.com.crt
SSLCertificateKeyFile /etc/apache/ssl/example.key
SSLCertificateChainFile /etc/apache/ssl/gd_bundle.crt
ErrorLog "/var/www/example.com/error.log"
CustomLog "/var/www/example.com/access.log" combined
</VirtualHost>

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>