Let's Encypt for Laravel Application with Nginx on LEMP Ubuntu 16.04

August 6, 2018 206 views
Let's Encrypt Nginx Ubuntu 16.04

Hi everyone,

First time for everything here (DigitalOcean, Laravel, Github, etc). Sorry in advance for my ignorance.

I have successfully been able to deploy the Marketplacekit app on my Ubuntu 16.04 LEMP droplet.

I have been using a combination of these great tutorials from DigitalOcean.

(1) How To Deploy a Laravel Application with Nginx on Ubuntu 16.04
(2) How To Install Linux, Nginx, MySQL, PHP (LEMP stack) in Ubuntu 16.04

I am currently trying to install Let's Encypt SSL certificates across my domain (Step 6 of tutorial (1)).

Originally after following step 6 I got these errors:

    include snippets/ssl-example.com.conf;
    include snippets/ssl-params.conf;

Another user had the same errors as the files did not exist using the tutorial method. So I tried to manually create the files using these steps.

It seems that the SSL is working properly, but now I am getting 404 Not Found error.

sudo nano /etc/nginx/sites-enabled/example.com
is as follows:

server {
        listen 80;
        listen [::]:80;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html/marketplacekit/public;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name example.com www.example.com;
        return 301 https://$server_name$request_uri;


        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$query_string;
        }


        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }



        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #       include snippets/fastcgi-php.conf;
        #
        #       # With php7.0-cgi alone:
        #       fastcgi_pass 127.0.0.1:9000;
        #       # With php7.0-fpm:
        #       fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #       deny all;
        #}
}


server {
        listen 443 ssl http2;
        listen [::]:443 ssl http2;

        include snippets/ssl-example.com.conf;
        include snippets/ssl-params.conf;

        root /var/www/html/quickstart/public;

        index index.php index.html index.htm index.nginx-debian.html;

        server_name example.com www.example.com;

        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }

        location ~ /\.ht {
                deny all;
        }

        location ~ /.well-known {
                allow all;
        }
}