Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Homestead - SSL set up

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.

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

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

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

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

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

If I then try to access pages using http I get a 400 error 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?

Very confused to a completely new subject

Thank you

like image 272
Ray Avatar asked Jan 10 '23 22:01

Ray


2 Answers

Add port forwarding to homestead 1.x

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

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

Create SSL certificate

Steps one to four

Do the steps one to step four only from this tutorial 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 listen line as you did). In the duplicated section edit listen 80 to listen 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;

exit and do a vagrant reload.

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

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

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

like image 108
Pᴇʜ Avatar answered Jan 25 '23 14:01

Pᴇʜ


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

listen 443 ssl;
like image 26
Jules Avatar answered Jan 25 '23 15:01

Jules