Loading...

Deploy Laravel Application on AWS ElasticBeanstalk on Nginx Server and upload SSL certificate

Last updated: Dec 21st 2024

Deploy Laravel Application on AWS ElasticBeanstalk on Nginx Server and upload SSL certificate

First you would need to obtain the SSL certificate which you could do either from freessl.com or from AWS directly. Within your laravel application create a folder ".ebextensions". Create two files as follows:

  • https-instance.config
  • https-instance-single.config
  • .platform/nginx/conf.d/elasticbeanstalk/extra.conf

In the https-instance.confg add the following which essentially creates and saves the certificate files on the EC2 instance through the ELB deployment.



files:
  /etc/pki/tls/certs/server.crt:
    content: |
        -----BEGIN CERTIFICATE-----
        THE CA BUNDLE AND THE CERTIFICATE CONTENT COMES HER. 
        -----END CERTIFICATE-----

  /etc/pki/tls/certs/server.key:
    content: |
      -----BEGIN RSA PRIVATE KEY-----
      YOUR_KEY_CONTENT_COMES_HERE
      -----END RSA PRIVATE KEY-----

container_commands:
  01restart_nginx:
    command: "service nginx restart"


In the https-instance-single.config add the following



Resources:
  sslSecurityGroupIngress:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
      IpProtocol: tcp
      ToPort: 443
      FromPort: 443
      CidrIp: 0.0.0.0/0

In the extra.conf put the following which essentially allows the NGINX server to listen on port 443.




listen              443 ssl;
		ssl_certificate     /etc/pki/tls/certs/server.crt;
		ssl_certificate_key /etc/pki/tls/certs/server.key;
location / {
           try_files $uri $uri/ /index.php$is_args$args;
        }


Note: remember to pay attention to the indentations and spaces as these are yaml files and are sensitive. They may not work if the indentations aren't correct. That should do it.

SYED ABDUL QUADER Published on 25 Oct 2020
Edit
Comments
Guest User