Forcing HTTP redirect to HTTPS is ignoring subdomains - apache

I have set up a Apache server with the 3 virtual hosts tomrouse.me, dev.tomrouse.me and server.tomrouse.me. All of the virtual hosts worked fine. When I went to each one, it would take me to the index for that site.
But when I added SSL and forced HTTP to redirect to HTTPS, it is now always going to the tomrouse.me virtual host no matter what subdomain I request.
Files I have in available sites in Apache:
SSL configuration for Apache:
I dont think it is a issue with the virtual hosts, as all were working fine until I added SSL with redirects using the python-letsencrypt-apache program.

All fixed, i went wrong by trying to install the ssl in all sub domains at once did a full reinstall then did each one one at a time and it works fine!
For example:
This is what it tells you to do (this will not work):
sudo letsencrypt --apache -d tomrouse.me -d dev.tomrouse.me -d server.tomrouse.me
I reinstalled the server the same but did this part like this:
sudo letsencrypt --apache -d tomrouse.me
sudo letsencrypt --apache -d dev.tomrouse.me
sudo letsencrypt --apache -d server.tomrouse.me
and selected the force https like i did before for each this is a fix if you have the same issie however if you already did it the first way you have to restart as far as i know i tryed doing this after the first way and it dint work.
Correct format of apache config files:
All of the ssl config files should be created by the lets encrypted program https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-16-04

Related

Certbot / letsencrypt Error with [non-www] domain after generating [www] certificate

I setup two sites (links below) using certbot and entered the "www." portion of the domain when generating the HTTPS certificate resulting in non-www URL's for both sites causing an error.
There are many similar questions on StackOverflow but none have fixed my issue so far.
Related Links
https://certbot.eff.org/lets-encrypt/ubuntubionic-apache
https://letsencrypt.org/
Working Domains
https://www.fastsitephp.com/en/
https://www.dataformsjs.com/#/en/
Invalid Domains (because of the missing 'www.')
https://fastsitephp.com/en/
https://dataformsjs.com/#/en/
Attempted Fix Commands
sudo certbot certonly --standalone -d fastsitephp.com -d www.fastsitephp.com
sudo certbot delete --cert-name www.fastsitephp.com
Chrome will re-direct to the 'www' site using the above links however the error is clear from Firefox and Mobile Safari
Server
Ubuntu 18.04 LTS with Apache
HELP! What can I do to fix this without having to setup a new server and changing the URL. Ideally the severs would support both www and non-www; however if it can't be fixed an Apache url re-write would also be acceptable.
Thank you in advance!
I ended up solving it myself. The primary issue is that Certbot still leaves the HTTP->HTTPS redirect it created and some other Apache config settings even after running delete (this assumes you selected redirect from HTTP to HTTPS on the original setup).
In case someone else has this issue and needs to fully delete a certificate generated by Certbot here are the commands that I used:
sudo certbot delete
cd /etc/apache2/sites-enabled
ls
sudo nano 000-default.conf
# Remove the redirect
sudo rm 000-default-le-ssl.conf
# Also any file other SSL files such as [000-default-le-ssl.conf.sav]
sudo certbot --apache
# enter both Domains "example.com www.example.com"
sudo service apache2 restart

Wildcard SSL certificates for multiple subdomain

I have a system with multiple clients. Each client has their own subdomain.
client1.example.com
client2.example.com
...
At the server side, all requests are redirected to *.example.com. Then my business logic reads the subdomain (like client1) and gives response to the client accordingly.
So basically, I do not configure each subdomain on the server. I just add it to my database and my code handles it properly.
I am trying to apply wildcard SSL certificates to all these subdomains. Also, I want all future clients to automatically get https.
But I don't know how to configure this. I have tried using Let's Encrypt, but no luck. The actual domain example.com gets https but not the client domains.
Any help with configuration would be really helpful.
Or, may be, this setup is just not possible. I don't know.
Please help.
P.S. example.com is just a dummy domain I am referring to.
P.P.S. I use apache2 web server on Ubuntu 16.04 x64
Well, it is possible. I now have a certificate in place for *.example.com and it works on all my arbitrary subdomains, viz.,
client1.example.com
client2.example.com
...
I followed these steps:
$ wget https://dl.eff.org/certbot-auto
$ chmod a+x ./certbot-auto
$ sudo ./certbot-auto certonly \
--server https://acme-v02.api.letsencrypt.org/directory \
--manual --preferred-challenges dns \
-d *.example.com
Then using the files created at /etc/letsencrypt/live/example.com/, I updated the values from my control panel (I use Vestacp)
cat /etc/letsencrypt/live/example.com/cert.pem
^ Copy contents into “SSL Certificate” field.
cat /etc/letsencrypt/live/example.com/privkey.pem
^ Copy contents into “SSL Key” field.
cat /etc/letsencrypt/live/example.com/chain.pem
^ Copy contents into “SSL CA / Intermediate” field.
Make changes according to your control panel.
Follow this article for detailed steps and explanation.

Apache plugin not working for Let's Encrypt

I'm trying to secure my CentOS 7 VPS with Let's Encrypt. I've followed the guidelines in https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-centos-7 . I've set up virtual hosts, installed server dependencies and the Let's Encrypt client. But when I try to set up the SSL certificate with:
./letsencrypt-auto --apache -d example.com -d mail.example.com
I get the error:
The apache plugin is not working; there may be problems with your existing configuration.
The error was: NoInstallationError()
The Apache Plugin for Let's Encrypt is not working, but how do I make it work?
Same error on CentOS 7 and Apache 2.4. Checked through my configuration, had a couple of IfModule lines that were not closed with /IfModule. Apache is OK with them, but apparently certbot parser isn't. Hope this helps others.
appretnly they are a bug in the letsencrypt-auto script, you can use this command to do the job.
sudo certbot --authenticator standalone --installer apache -d <yourdomain> --pre-hook "systemctl stop apache2" --post-hook "systemctl start apache2"
This answer is not working. In my cases i checked apache config file and found the following line at the end of it <IfModule mod_ssl.c> It was not making sense. On removing it the renewal went on without a problem

Change webroot-path of registered letsencrypt cert

I am new with Let's Encrypt certificate. I registered my domain for a nginx server at digitalocean.com following this command
cd /opt/letsencrypt ./letsencrypt-auto certonly -a webroot
--webroot-path=/usr/share/nginx/html -d mydomain.com -d www.mydomain.com
and it works fine. Then i have changed my webroot path to /var/www/xxx for my domain.
Now when i trying to renew my letsencrypt certificate it's getting error.
Then i rollback my webroot path, try again and the renewal works perfectly.
Now my question is how can i change my registered webroot-path for Let's Encrypt?
change it in /etc/letsencrypt/renewal/mydomain.conf
set
authenticator = webroot
webroot_path=/var/www/xxx/
and key moment that took me several hours to figure out - configure webrooth path with webroot_path=/var/www/xxx/ not with webroot-path=/var/www/xxx, note the underscore
You don't have to roll back your webroot path in nginx, just change the webroot value when run let's encrypt script.
/opt/letsencrypt/letsencrypt-auto certonly -a webroot --webroot-path=/var/www/xxx -d mydomain.com -d www.mydomain.com
The letsencrypt script requires your webroot because the authentication is based on files that added to your webroot, which should be under /.well-known/acme-challenge/, the authentication process including external requests to those files so if the two webroot values doesn't match, you will see an error because the auth server couldn't reach that file. Every time you try to get/renew a cert, just make sure you pass exact the same root value from nginx to let's encrypt.

Update Let's Encrypt Configuration on Apache

Hi i set up Let's Encrypt within Debian.
Now it works fine when i put https://example.com but it does not work fine
when i put https://www.example.com
i used the following command ./letsencrypt-auto --apache -d example.com
instead of ./letsencrypt-auto --apache -d example.com -d www.example.com
I performed the last command but the it still not working thus what can i do to
have https://www.example.com working ?
Thanks
You have th execute the following command :
./letsencrypt-auto --apache -d example.com -d www.example.com
I just went through the process of generating a single Let's Encrypt certificate for multiple subdomains. There were some minor challenges that I encountered and resolved. I posted a short article in the link below explaining the leasons learned I gained when installing Let's Encrypt digital certificates on my Apache web server which provides HTTP and HTTPS access to multiple subdomains.
My most important "lesson learned" is that you need to create a VirtualHost for the HTTP access AND a VirtualHost for each subdomain accessible via HTTPS. IMPORTANT: Each VirtualHost definition must be specified in a single configuration file. The Let's Encrypt certbot will not operate correctly if multiple VirtualHosts are defined within a single configuration file. I defined three (3) VirtualHosts in three (3) different configuration files below. The dummy.conf file serves no functional purpose within Apache (i.e., it will not cause an unnecessary 999 listening port), but it is absolutely necessary for digital certificates to be successfully generated by the Let's Encrypt certbot.
Then you can run the following command to generate the certificate:
certbot --apache -d example.com -d www.example.com
https://www.hueyise.com/index.php/letsencrypt