Laravel-php-artisan用于模拟HTTPS


Laravel php artisan serve to mimic HTTPS

我一直在四处搜索,看看是否有一种方法可以模拟SSL用于本地开发,使用Laravel的artisan来提供HTTPS,但运气不佳。

这可能吗?如果可能,怎么做?

我知道这是一个非常普遍的问题,但我在搜索中没有看到任何关于这方面的内容。

您可以将ngrok用于

php artisan serve
cd <path-to-ngrok>
./ngrok http localhost:8000

https://ngrok.com/

Laravel使用内置的PHP5.4开发服务器php -S(http://php.net/manual/en/features.commandline.webserver.php)因为它是artisan serve命令(参见Illuminate'Foundation'Console'ServeCommand)。这只支持纯HTTP,所以不,这是不可能的。你最好的选择是使用一个设置为使用SSL/TLS的Vagrant盒子。

如果您使用的是xampp,那么您可以使用xampp在本地设置HTTPS(这篇文章对设置HTTPS也很有用),然后您可以:

  1. 将您的项目移动到htdocs文件夹并使用https://localhost/projectFolder/public/ 进行访问

  2. 或者在httpd-vhosts.conf中为该项目创建一个特殊的VirtualHost(始终指向public文件夹,这是项目运行的地方),然后在本例中使用https://localhost/访问它(当然,如果你愿意,你可以在子域上运行它)

    <VirtualHost *:80>
        ServerName localhost
        DocumentRoot "c:'pathToYourProject'projectFolder'public"
        <Directory "c:'pathToYourProject'projectFolder'public">
            Options All
            AllowOverride All
        </Directory>
    </VirtualHost>
    # this should ensure https (this is mentioned in the stackoverflow post, that I linked as useful
    <VirtualHost *:443>
        ServerName localhost
        DocumentRoot "c:'pathToYourProject'projectFolder'public"
        SSLEngine on
        SSLCertificateFile "conf'ssl.crt'server.crt"
        SSLCertificateKeyFile "conf'ssl.key'server.key"
        <Directory "c:'pathToYourProject'projectFolder'public">
            Options All
            AllowOverride All
        </Directory>
    </VirtualHost>
    

从理论上讲,当你使用这种方法时,你甚至不需要php artisan serve(我不完全确定它在这种情况下是否有任何用途)。