Laravel Homestead - SSL 设置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25558426/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 10:01:03  来源:igfitidea点击:

Laravel Homestead - SSL set up

ssllaravelvagrant

提问by Ray

I'm trying to start to use vagrant for development - I'm completely new to using vagrant for my development - relying on an apache/php/mysql set up on a laptop.

我正在尝试开始使用 vagrant 进行开发 - 我对使用 vagrant 进行开发完全陌生 - 依靠笔记本电脑上设置的 apache/php/mysql。

I'm developing using laravel and have set up homestead and am up and running.

我正在使用 laravel 进行开发,并且已经建立了 homestead 并且正在运行。

I've tried to enable SSL on the homestead (box?) and followed these instructions to set up: https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-nginx-for-ubuntu-12-04

我尝试在宅基地(盒子?)上启用 SSL,并按照以下说明进行设置:https: //www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on- nginx-for-ubuntu-12-04

I made the changes to the homestead sites_enabled file for the site i'm working on.

我对我正在处理的站点的 homestead sites_enabled 文件进行了更改。

I added port 443 just beneath port 80 within the server,added the entries for SSL On etc

我在服务器内的端口 80 正下方添加了端口 443,添加了 SSL On 等的条目

I've restarted the nginx server and am able to see my pages using https (although chrome doesn't like the certificate)

我已经重新启动了 nginx 服务器,并且能够使用 https 查看我的页面(尽管 chrome 不喜欢证书)

If I then try to access pages using http I get a 400 error The plain HTTP request was sent to HTTPS port

如果我然后尝试使用 http 访问页面,我会收到 400 错误 The plain HTTP request was sent to HTTPS port

so a few questions: 1. how can I alter the set up to use a combination of HTTP and HTTPS requests? 2. is it bad practice to serve a site with a combination of HTTP and HTTPS requests - should I simply serve the whole site as https?

所以有几个问题: 1. 如何更改设置以使用 HTTP 和 HTTPS 请求的组合?2. 使用 HTTP 和 HTTPS 请求的组合为站点提供服务是不好的做法 - 我应该简单地将整个站点作为 https 提供服务吗?

Very confused to a completely new subject

对一个全新的主题非常困惑

Thank you

谢谢

回答by P??

Add port forwarding to homestead 1.x

为 homestead 1.x 添加端口转发

You need to forward the SSL port by adding a new line to homestead.rb

您需要通过向 homestead.rb 添加新行来转发 SSL 端口

sudo nano /vagrant/scripts/homestead.rb  
# add SSL port forwarding ...
config.vm.network "forwarded_port", guest: 443, host: 44300

Create SSL certificate

创建 SSL 证书

Steps one to four

步骤一到四

Do the steps oneto step fouronly from this tutorial https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-nginx-for-ubuntu-12-04

仅从本教程中执行第一步第四步https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-nginx-for-ubuntu-12-04

Step five - Set up the certificate

第五步 - 设置证书

Edit your homestead site you are working on (replace example with your existing site)

编辑您正在处理的宅基地网站(用您现有的网站替换示例)

sudo nano /etc/nginx/sites-available/example

Duplicate the whole server{…}section (not only the listenline as you did). In the duplicated section edit listen 80to listen 443.

复制整个server{…}部分(不仅listen是您所做的那一行)。在复制部分编辑listen 80listen 443.

Before the end of the section add the following lines:

在本节末尾添加以下几行:

ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;

exitand do a vagrant reload.

exit并做一个vagrant reload.

Be careful with --provision. The changes to sites-available/exampleyou just made are reset to default.

小心--provision. sites-available/example您刚刚所做的更改将重置为默认值。

If you need to make the changes permanently even in case of provisioning, then have a look at the serve.shlocated at your host's homestead folder homstead/scripts/serve.shand edit it equally to step 5.

如果即使在配置的情况下也需要永久进行更改,请查看serve.sh位于主机的 homestead 文件夹中的homstead/scripts/serve.sh并将其编辑为与第 5 步相同的内容。

Use https://your.domain:44300in your browser to access via SSL. Accept the self signed certificate in your browser if necessary.

使用https://your.domain:44300浏览器通过SSL访问。如有必要,请在浏览器中接受自签名证书。

回答by Jules

In addition to Peh. I did not get it working with the above code:

除了佩。我没有让它与上面的代码一起工作:

I did need to remove

我确实需要删除

SSL on

and add the ssl to the listener

并将 ssl 添加到侦听器

listen 443 ssl;