【问题标题】:Let's Encypt for Laravel Application with Nginx on LEMP Ubuntu 16.04让我们在 LNMP Ubuntu 16.04 上使用 Nginx 为 Laravel 应用程序加密
【发布时间】:2019-01-13 21:35:50
【问题描述】:

第一次接触这里的一切(DigitalOcean、Laravel、Github 等)。提前为我的无知道歉。

我已经成功地在我的 Ubuntu 16.04 LEMP droplet 上部署了 Marketplacekit 应用程序。在尝试安装 SSL 之前,一切正常。

我一直在使用来自 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

我目前正在尝试在我的域中安装 Let's Encypt SSL 证书(教程 (1) 的第 6 步)。

最初在执行第 6 步后出现以下错误:

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

另一个用户使用教程方法遇到了相同的错误,因为文件不存在。所以我尝试使用他们建议的these steps 手动创建文件。

似乎 SSL 工作正常,但 现在我收到 404 Not Found 错误。

这是我启用的配置文件:

sudo nano /etc/nginx/sites-enabled/example.com

--

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;
            }
    }

【问题讨论】:

  • 您按照什么教程来安装 Let's Encrypt?这是我关注的:digitalocean.com/community/tutorials/… 你也可以查看这个:digitalocean.com/community/tutorials/…
  • 我在您使用的那个上执行了步骤 1-3。然后跳到我链接的 (1) 教程中的第 6 步。 sudo certbot certonly --webroot --webroot-path=/var/www/html/marketplacekit/public -d example.com -d www.example.com
  • 您是否为您的域更改了-d example.com -d www.example.com 对吗?
  • 是的,当我访问该站点时,该站点是安全的,但它给出了 404。所以看起来 SSL 工作正常,只是配置不正确。

标签: php laravel ubuntu nginx lets-encrypt


【解决方案1】:

我想出了如何让它发挥作用。

  1. 删除 /etc/nginx/sn-ps/ssl-example.com.conf
  2. 删除 /etc/nginx/sn-ps/ssl-params.conf
  3. 删除 /etc/ssl/certs/dhparam.pem

按照本教程删除并重新创建启用了 nginx 的配置文件并安装 SSL。

Follow this tutorial instead

配置文件看起来像这样,最后一部分是在安装证书时自动创建的。

server {

    # 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;


    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;
    #}

listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/example.com-0001/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/example.com-0001/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

【讨论】:

    【解决方案2】:

    Let's encrypt 提供免费的 SSL,就像是小型初创公司和开发人员的教父。如果你在 Ubuntu 中使用 nginx,那么你不需要自己做任何事情。只需安装 certbot 进行加密,它就会在启用站点的文件中自行进行所需的配置。如果您仍然面临问题,那么我建议您阅读有关如何 install let's encrypt on nginx for laraval 的教程

    【讨论】:

      猜你喜欢
      • 2020-06-29
      • 1970-01-01
      • 1970-01-01
      • 2018-08-30
      • 1970-01-01
      • 1970-01-01
      • 2017-08-11
      • 2021-01-28
      • 2018-03-30
      相关资源
      最近更新 更多