【问题标题】:Setup HTTPS on wildcard subdomain on localhost在 localhost 上的通配符子域上设置 HTTPS
【发布时间】:2014-11-14 20:46:47
【问题描述】:

我在本地 Ubuntu 机器上创建了一个 Laravel 应用程序。但我想在其所有通配符子域上使用HTTPS。我怎样才能在本地做到这一点?顺便说一句,我已经在 etc/hosts 添加了我的网站 URL,所以我不需要输入 localhost 而是输入 www.mysite.loc

回答这个问题How can I install SSL on localhost in Ubuntu?,我认为只适用于主域。

【问题讨论】:

    标签: php apache .htaccess ssl laravel


    【解决方案1】:

    不,这个问题的答案How can I install SSL on localhost in Ubuntu? 工作正常。但是您需要修改conf 文件中的几行代码。

    我现在设法尝试了它并且工作正常,但是我从浏览器收到了这条令人恼火的消息,表明我正在访问的网站不安全。虽然没关系,因为它只是自签名证书。

    在我的/etc/hosts 中,我为我的本地站点添加了几个子域,因为即使您正确配置了虚拟主机,它也无法正常工作,因为您开发的站点尚未在线访问。

    说,www.mydomain.comhello.mydomain.comworld.mydomain.com

    现在,我们需要启用 SSL 模块

    sudo a2enmod ssl

    重启 Apache

    sudo service apache2 restart

    为自签名 SSL 证书创建一个文件夹

    sudo mkdir /etc/apache2/ssl

    为 SSL 生成密钥和其他东西

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

    回答他们的问题并使用您的域说mydomain.com as Common name

    现在我编辑了位于/etc/apache2/sites-available/mydomain.com.conf的虚拟主机的conf文件

    这是里面的东西

    <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>
    

    如果您已经启用了虚拟主机,则需要跳过此步骤。否则,输入

    sudo a2ensite mydomain.com.conf

    最后,你需要通过

    再次重启Apache

    sudo service apache2 restart

    希望对你有帮助!您现在可以使用https访问您的网站

    例如。 https://www.mydomain.comhttps://hello.mydomain.comhttps://world.mydomain.com

    【讨论】:

    • 哇,谢谢。我现在需要设置这个。如果它有效,我稍后会接受它。
    猜你喜欢
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 2010-10-03
    • 2016-08-23
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多