在 laravel 应用程序、Apache、Ubuntu 20.04 上安装 Certbot 软件并配置 HTTPS 后 HTTPS:// 链接断开 |数字海洋

Posted

技术标签:

【中文标题】在 laravel 应用程序、Apache、Ubuntu 20.04 上安装 Certbot 软件并配置 HTTPS 后 HTTPS:// 链接断开 |数字海洋【英文标题】:Broken HTTPS:// links after Installing Certbot software and configuring HTTPS on laravel application, Apache, Ubuntu 20.04 | DigitalOcean 【发布时间】:2021-02-13 21:59:10 【问题描述】:

我在 Digital Ocean 的 Apache Ubuntu 20.04 上成功部署了 Laravel 应用程序,一切都很好,直到我安装 CertBot 软件在我的 Apache 服务器上配置 HTTPS。安装和设置 certbot 后,当我通过 HTTPS:// 链接访问主页时,它工作正常,但是当我尝试通过 HTTPS:// 链接访问其他页面时,出现以下错误:

找不到

在此服务器上找不到请求的 URL。 Apache/2.4.41 (Ubuntu) 服务器位于 mysite.com 端口 443

我按照此链接中的指南进行操作:https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-20-04

下面是我的 Apache 配置文件

mysite.com.conf

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName mysite.com
        ServerAlias www.mysite.com
        DocumentRoot /var/www/mysite.com/mysite-web-app/public

        <Directory /var/www/mysite.com/mysite-web-app/public>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog $APACHE_LOG_DIR/error.log
        CustomLog $APACHE_LOG_DIR/access.log combined

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

RewriteEngine on
RewriteCond %SERVER_NAME =www.mysite.com [OR]
RewriteCond %SERVER_NAME =mysite.com
RewriteRule ^ https://%SERVER_NAME%REQUEST_URI [END,NE,R=permanent]
</VirtualHost>

mysite.com-le-ssl.conf

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerAdmin webmaster@localhost
    ServerName mysite.com
    ServerAlias www.mysite.com
    DocumentRoot /var/www/mysite.com/mysite-web-app/public
    ErrorLog $APACHE_LOG_DIR/error.log
    CustomLog $APACHE_LOG_DIR/access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mysite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.com/privkey.pem
</VirtualHost>
</IfModule>

【问题讨论】:

【参考方案1】:

您也必须在 ssl conf 中包含此内容:

    <Directory /var/www/mysite.com/mysite-web-app/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    <IfModule mod_dir.c>
        DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
    </IfModule>

否则 .htaccess 将不适用于 https 连接。

【讨论】:

非常感谢。它像魔术一样工作。你刚刚救了一条命。我已经坚持了三天。再次感谢您。 哇!很高兴我能帮助你! :)

以上是关于在 laravel 应用程序、Apache、Ubuntu 20.04 上安装 Certbot 软件并配置 HTTPS 后 HTTPS:// 链接断开 |数字海洋的主要内容,如果未能解决你的问题,请参考以下文章

sersync实现实时同步

sersync实现实时同步

web服务器(LAMP)通过DNS轮询功能和nfs共享实现负载均衡

linux 文件共享技巧

Nginx安装配置

kubernetes nfs storage class arm64