gpt4 book ai didi

php - 让我们在 LNMP Ubuntu 16.04 上使用 Nginx 为 Laravel 应用程序加密

转载 作者:行者123 更新时间:2023-12-04 18:50:43 24 4
gpt4 key购买 nike

第一次在这里做所有事情(DigitalOcean、Laravel、Github 等)。提前为我的无知道歉。

我已经成功部署了Marketplacekit我的 Ubuntu 16.04 LEMP 液滴上的应用程序。在尝试安装 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;
}
}

最佳答案

我想出了如何让它工作。

  • 删除/etc/nginx/snippets/ssl-example.com.conf
  • 删除/etc/nginx/snippets/ssl-params.conf
  • 删除/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

    }

    关于php - 让我们在 LNMP Ubuntu 16.04 上使用 Nginx 为 Laravel 应用程序加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51715871/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com