Reputation: 101
I'm setting up a new example and putting it on a virtual host Apache server (Ubuntu 18.04). I'm having some issues with the Apache configuration because I'm not too familiar with them.
http://example.com
, http://www.example.com
, https://www.example.com
all serve the correct website in its document root.
However, https://example.com
serves the document root from main-example.org
.
I have also installed an SSL certificate recently and been told to use port 443? It still comes up as "Connection not sure" so I was wondering if this were the case?
Here is the config file in apache2/sites-available
:
<VirtualHost *:80>
ServerName main-example.org
ServerAlias www.main-example.org
ServerAdmin [email protected]
DocumentRoot /var/www/main-example/build
ErrorLog /var/www/main-example/error_test.log
CustomLog /var/www/main-example/access_test.log combined
<Directory "/var/www/main-example">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/example
ErrorLog ${APACHE_LOG_DIR}/error_test.log
CustomLog ${APACHE_LOG_DIR}/access_test.log combined
<Directory "/var/www/example">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =main-example.org [OR]
RewriteCond %{SERVER_NAME} =www.main-example.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Thanks for your help!
Upvotes: 2
Views: 30
Reputation: 3372
http://
has a default port 80
https://
has a default port 443
Since https
uses encryption, if you just put the encryption on 80
, all the clients that cannot talk securely will be unable to access yous site (and you'd have to write https://www.example.com:80
)
So you have to do something like this:
<VirtualHost *:80>
ServerName main-example.org
ServerAlias www.main-example.org
ServerAdmin [email protected]
DocumentRoot /var/www/main-example/build
ErrorLog /var/www/main-example/error_test.log
CustomLog /var/www/main-example/access_test.log combined
<Directory "/var/www/main-example">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/example
ErrorLog ${APACHE_LOG_DIR}/error_test.log
CustomLog ${APACHE_LOG_DIR}/access_test.log combined
<Directory "/var/www/example">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =example.com [OR]
RewriteCond %{SERVER_NAME} =main-example.org [OR]
RewriteCond %{SERVER_NAME} =www.main-example.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:443>
ServerName main-example.org
ServerAlias www.main-example.org
ServerAdmin [email protected]
DocumentRoot /var/www/main-example/build
ErrorLog /var/www/main-example/error_test.log
CustomLog /var/www/main-example/access_test.log combined
<Directory "/var/www/main-example">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLEngine on
#SSLCipherSuite HIGH
SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
SSLProtocol all -SSLv2
SSLCertificateFile "/path/to/ssl.crt"
SSLCertificateKeyFile "/path/to/ssl.k
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/example
ErrorLog ${APACHE_LOG_DIR}/error_test.log
CustomLog ${APACHE_LOG_DIR}/access_test.log combined
<Directory "/var/www/example">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
SSLEngine on
#SSLCipherSuite HIGH
SSLCipherSuite ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
SSLProtocol all -SSLv2
SSLCertificateFile "/path/to/ssl.crt"
SSLCertificateKeyFile "/path/to/ssl.key"
</VirtualHost>
essentially this means that you are serving he same folder twice. there may be some optimizations to be found.
For more protocols and their standard port numbers see https://opensource.com/article/18/10/common-network-ports or https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
Upvotes: 1