Configuring HTTPS for a wildcard subdomain on localhost

I have created an application Laravel

on my local Ubuntu machine. But I want to use HTTPS

wild card for all my subdomains. How can I do this locally? By the way, I added my site url to etc/hosts

, so I don't have to type localhost

, but instead www.mysite.loc

.

Answer this question How to install SSL on localhost in Ubuntu? , I think it will only work on the main domain.

+3


source to share


1 answer


No, the answer to this question is How to install SSL on localhost in Ubuntu? works fine. But you need to change a few lines of code in the file conf

.

I was able to try it now and work great, but I got an annoying message from my browser stating that the site I am accessing is not secure. Although this is ok as it is only the signed certificate itself.

In mine, /etc/hosts

I have added some subdomains for my local site, as it won't work even if you set up your virtual host correctly, because the site you are developing on is not online yet.

Say, www.mydomain.com

, hello.mydomain.com

,world.mydomain.com

Now we need to enable the SSL module

sudo a2enmod ssl

Restart Apache

sudo service apache2 restart

Create a folder for self-signed SSL certificates

sudo mkdir /etc/apache2/ssl

Generate key and other files for SSL

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt



Answer questions and use your domain, let's say mydomain.com

howCommon name

Now I have edited conf

my virtual host file which is in/etc/apache2/sites-available/mydomain.com.conf

This is what's inside

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
    ServerAdmin admin@example.com
    ServerName www.mydomain.com
    ServerAlias mydomain.com *.mydomain.com
    DocumentRoot /home/me/projects/www/mysite_folder
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/apache.crt
    SSLCertificateKeyFile /etc/apache2/ssl/apache.key
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>   

    <Directory "/home/me/projects/www/mysite_folder">
       SSLOptions +StdEnvVars
       Order allow,deny
       Allow from all
       # New directive needed in Apache 2.4.3: 
       Require all granted
       AllowOverride All
    </Directory>
    BrowserMatch "MSIE [2-6]" \
                    nokeepalive ssl-unclean-shutdown \
                    downgrade-1.0 force-response-1.0
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>

      

If you have already enabled your virtual host, you need to skip this step. Else, enter

sudo a2ensite mydomain.com.conf

Finally, you need to restart Apache again with

sudo service apache2 restart

Hope this helps you! You can now access your site withhttps

Ex. https://www.mydomain.com

, https://hello.mydomain.com

,https://world.mydomain.com

+2


source







All Articles