Re: How to deal with www and non-www domain names with one certificate?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Ed,
When I am setting up a server or virtual host, I start with this:
https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess

That's the configuration file from a project that is intended to jumpstart web development projects and set smart defaults. It is well documented particularly with inline comments.

I believe the default configuration is what you're describing but if you need to make adjustments you can just comment or uncomment the appropriate settings for your use case.

I then use Certbot to generate an SSL certificate that covers both the naked domain and the www subdomain (and any other subdomains).

These 2 documents outline how to set up the configuration files:
https://httpd.apache.org/docs/2.4/configuring.html
https://httpd.apache.org/docs/2.4/sections.html

My suggestion would be to use the code in the HTML5 Boilerplate (the first link) but do so in your main config file so that you avoid using `.htaccess` files (and `AllowOverride` directives) altogether.

Another tool you might find useful is the Mozilla SSL configuration generator

It looks like you shared both the public and private encryption keys when you included the SSL certificates so you should generate new keys/certificates.

Hope that helps.

-Adam Powell
Founder, ADA First

On Tue, Feb 4, 2020 at 1:03 PM edflecko . <edflecko@xxxxxxxxx> wrote:
I don't understand how to deal with forcing all connections to www.sierraprogress.org to simply sierraprogress.org , forcing all connections to my website with https , and using only one certificate per domain name?

Here's my unique server information:
CentOS 7
Server version: Apache/2.4.41 (codeit)
OpenSSL 1.1.1c

1.) Forcing all connections to www.domainname.com to domainname.comis best done with a rewrite rule, isn't it? I've found some examples online, but I don't know if one is better than the others?

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^([^.]+)\.sierraprogress\.org$ [NC]
RewriteRule ^(.*)$ https://sierraprogress.org/$1 [R=301,L]

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sierraprogress\.org$ [NC]
RewriteRule ^ https://www. sierraprogress.org %{REQUEST_URI} [R=301,L]

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.sierraprogress.org
RewriteRule (.*) https:// sierraprogress.org /$1 [R=301,L]

Since I want ALL websites that this server will host to remove the www AND be https connections, maybe the first example is best?

Do I just place this code snippet in my httpd.conf file?

2.) Here's my sierraprogress.org.conf file:

<VirtualHost *:80>
    ServerName sierraprogress.org
    ServerAlias www.sierraprogress.org
DocumentRoot /var/www/sierraprogress.org/public_html
<Directory /var/www/sierraprogress.org/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>
    ErrorLog /var/www/sierraprogress.org/error.log
    CustomLog /var/www/sierraprogress.org/requests.log combined
</VirtualHost>

<VirtualHost *:443>
    DocumentRoot /var/www/sierraprogress.org/public_html
    Protocols h2 h2c http/1.1
    ServerName sierraprogress.org
    ServerAlias www.sierraprogress.org
<Directory /var/www/sierraprogress.org/public_html>
        Options -Indexes +FollowSymLinks
        AllowOverride All
    </Directory>
ErrorLog /var/www/sierraprogress.org/error.log
    CustomLog /var/www/sierraprogress.org/requests.log combined
    SSLEngine on
SSLCertificateFile /etc/httpd/ssl/sierraprogress.crt
    SSLCertificateKeyFile /etc/httpd/ssl/sierraprogress.key
SSLCipherSuite HIGH:!aNULL:!MD5
</VirtualHost>

The one certificate I'm using ( sierraprogress.crt) works fine for sierraprogress.org connections but, of course, will NOT work for www.sierraprogress.org connections because of the domain name mis-match. I've also tried using a wildcard certificate for *.sierraprogress.org (see below), but I couldn't get that to work at all.

Suggestions on how to handle these issues?

Thank you for your time and suggestions!
Ed

Certificate Decoder - https://www.sslshopper.com/certificate-decoder.html

-----BEGIN CERTIFICATE-----
MIIIRTCCBy2gAwIBAgIRAOKGYmn0tkDkNQnJmw6pxPUwDQYJKoZIhvcNAQELBQAwdjELMAkGA1UE
BhMCVVMxCzAJBgNVBAgTAk1JMRIwEAYDVQQHEwlBbm4gQXJib3IxEjAQBgNVBAoTCUludGVybmV0
MjERMA8GA1UECxMISW5Db21tb24xHzAdBgNVBAMTFkluQ29t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fBjRidj26h1oFBHZ7heDH1Bjzw72
hipu47Gkyfr2NEx3KoCGMLCj3Btx7ASn5Ji8FoU+hCazwOU1VX55mKPU1I2250Lo
RCASN18JyfsD5PVldJbtyrmz9gn/TKbRXTr80U2q5JhyvjhLf4lOJo/UzL5WCXED
Smyj4jWG3R7Z8TED9xNNCxGBMXnMete+3PvzdhssvbORDwBZByogQ9xL2LUZFI/i
eoQp0UM/L8zfP527vWjEzuDN5xwxMnhi+vCToh7J159o5ah29mP+aJnvujbXEnGa
nrNxHzu+AGOePV8hwrGGG7hOIcPDQwkuYwzN/xT29iLp/cqf9ZhEtkGcQcIImH3b
oJ8ifsCnSbu0GB9L06Yqh7lcyvKDTEADslIaeSEINxhO2Y1fmcYFX/Fqrrp1WnhH
OjplXuXE0OPa0utaKC25Aplgom88L2Z8mEWcyfoB7zKOfD759AN7JKZWCYwk
-----END CERTIFICATE-----

[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux