在 Laravel Homestead 上使用 SSL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45263265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use SSL on Laravel Homestead
提问by Parth Vora
I'm using Laravel Homestead and it is working fine. Now I want to implement HTTPS on one of my sites.
我正在使用 Laravel Homestead,它运行良好。现在我想在我的网站之一上实施 HTTPS。
I found that to achieve that you just need to add ssl: true
into Homestead.yaml and then run vagrant reload --provision.
我发现要实现这一点,您只需要添加ssl: true
到 Homestead.yaml 中,然后运行 vagrant reload --provision。
I can see it working when I run above command which shows:
当我运行上面显示的命令时,我可以看到它正在工作:
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Creating Certificate: laravel-cashier.local
==> homestead-7: Running provisioner: shell...
homestead-7: Running: script: Creating Site: laravel-cashier.local
And in /etc/nginx/ssl
, I can see these 3 files are created:
在 中/etc/nginx/ssl
,我可以看到创建了这 3 个文件:
-rw-r--r-- 1 root root 683 Jul 19 16:26 laravel-cashier.local.cnf
-rw-r--r-- 1 root root 1269 Jul 19 16:26 laravel-cashier.local.crt
-rw-r--r-- 1 root root 1704 Jul 19 16:26 laravel-cashier.local.key
But what next?
但是接下来呢?
When I'm trying to run the site with https:
当我尝试使用 https 运行站点时:
Do I need to do any other steps?
我需要做任何其他步骤吗?
Note: I'm using latest Homestead version 2.1.0.
注意:我使用的是最新的 Homestead 版本 2.1.0。
I have already seen many posts, but I think they are too old and doesn't provide exact steps to achieve the result:
我已经看过很多帖子,但我认为它们太旧了,没有提供实现结果的确切步骤:
https://laracasts.com/discuss/channels/tips/tip-how-to-enable-ssl-in-homestead-20
https://laracasts.com/discuss/channels/tips/tip-how-to-enable-ssl-in-homestead-20
https://laracasts.com/discuss/channels/servers/homestead-ssl
https://laracasts.com/discuss/channels/servers/homestead-ssl
回答by fquinto
I assume you are using Windows + Vagrantmachine with Homestead.
In this case laravel-cashier.local
is your web application.
我假设您在Homestead上使用 Windows + Vagrant机器。
在这种情况下是您的 Web 应用程序。laravel-cashier.local
You need to copy the certificate inside Vagrant, in Nginx to external folder:
您需要将 Nginx 中 Vagrant 中的证书复制到外部文件夹:
$ sudo cp /etc/nginx/ssl/laravel-cashier.local.crt ~/laravel-cashier/laravel-cashier.local.crt
$ sudo cp /etc/nginx/ssl/laravel-cashier.local.crt ~/laravel-cashier/laravel-cashier.local.crt
In Windows environment you can install this certificate with double-click and select the next specific storage:
在 Windows 环境中,您可以双击安装此证书并选择下一个特定存储:
Trusted Root Certification Authorities
受信任的根证书颁发机构
Restart your browser. Done.
重新启动浏览器。完毕。
More info about how to add certificate: https://technet.microsoft.com/en-us/library/cc754841(v=ws.11).aspx#BKMK_addlocal
有关如何添加证书的更多信息:https: //technet.microsoft.com/en-us/library/cc754841(v=ws.11).aspx#BKMK_addlocal
NOTE: This is valid for specific browser: Google Chrome
注意:这对特定浏览器有效:Google Chrome
回答by Chris Baldwin
It is as I first suspected and mentioned in my comment. You SSL config seems correct since it reports the connection is secure. You are using a self signed certificate, which is fine for development, but it not signed by a recognized Certificate Authority and therefore the browser will not trust it. However once you deploy your project to the general public you will want to purchase a certificate from a recognized Certificate Authority. Once you have that certificate then this error will go away.
正如我在评论中第一次怀疑和提到的那样。您的 SSL 配置似乎正确,因为它报告连接是安全的。您使用的是自签名证书,这对开发来说很好,但它不是由公认的证书颁发机构签名的,因此浏览器不会信任它。但是,一旦您将项目部署到公众,您将需要从公认的证书颁发机构购买证书。一旦您拥有该证书,此错误就会消失。
回答by Yevgeniy Afanasyev
This is only a year old question but it feels like it is a really old one.
这是一个只有一年历史的问题,但感觉它是一个非常古老的问题。
Fist - with a version 6.1.0 of 'laravel/homestead" vagrant box you don't need any ssl: true
, it is active by default, however your browser would not know if it can trust the ssl certificate anyway.
拳头 - 使用 6.1.0 版的“laravel/homestead”流浪盒,您不需要任何ssl: true
,默认情况下它处于活动状态,但是您的浏览器无论如何都不知道它是否可以信任 ssl 证书。
The browser trust is a different issue to laravel and homestead, please see thisanswer to solve it.
浏览器信任与 laravel 和 homestead 是不同的问题,请参阅此答案以解决它。