【问题标题】:Too many redirects error after installing ssl certificate安装 ssl 证书后出现太多重定向错误
【发布时间】:2020-02-03 09:47:31
【问题描述】:

安装 ssl 证书后,我的网站不再工作。我在 vps 上运行我的 cakephp 1.3 站点,它在没有 https 的情况下工作得很好,但是当我通过太多重定向错误启用 https 并且当我查看调试工具时,我看到来自 http (301) -> https (302) -> 的重定向循环http -> https

我在所有位置的 .htaccess 文件中添加了 mode_rewrite 规则

root -> .htaccess, app./.htaccess, app/webroot.htaccess 我也在代码中做了一些调整,但我发现当我启用 https 时它永远不会到达代码。现在我没有使用 .htacess,而是直接将我的虚拟主机指向 webroot 文件夹,但仍然得到重定向循环

我还检查了我的 dns 高级设置,发现没有问题。

重定向图片链接: https://gitlab.com/CPW2DO/newsite/uploads/a85856bcea45f463aa906916cf0025be/too_many_redirects_http.png

DNS 设置链接:

https://gitlab.com/CPW2DO/newsite/uploads/280ba2d0cbc8b2584726a26a94e76a4b/dns_settings.jpg

任何帮助将不胜感激提前感谢。

这是我的虚拟主机配置。

<VirtualHost *:80>
  DocumentRoot "/var/www/html/opa/staging/current/app/webroot"

  <Directory /var/www/html/opa/staging/current/app/webroot>
        Options Indexes FollowSymLinks MultiViews
#        AllowOverride All
#        Require all granted
        AllowOverride None
        Order deny,allow
        Allow from all

        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
   </Directory>

  ServerName opa-staging.capwell.nl
  ServerAlias www.opa-staging.capwell.nl
  Redirect permanent / https://opa-staging.capwell.nl/
  ErrorLog ${APACHE_LOG_DIR}/opa-staging-error.log
  CustomLog ${APACHE_LOG_DIR}/opa-staging-access.log combined
</VirtualHost>

<virtualhost *:443>
  DocumentRoot "/var/www/html/opa/staging/current/app/webroot"

  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/certificate.crt
  SSLCertificateKeyFile /etc/apache2/ssl/certificate.key
  SSLCertificateChainFile /etc/apache2/ssl/cabundle.crt
</virtualhost>

【问题讨论】:

  • 您的 HTTPS 配置还需要 HTTP 配置中的所有内容:目录、服务器名称等。默认情况下,它不会获取任何内容。
  • 伙计,你是个救命恩人,非常感谢我在这个问题上苦苦挣扎了 2 天。

标签: php ssl dns apache2 cakephp-1.3


【解决方案1】:

在关注@Greg Schmidt 评论后,我将我的 http 配置添加到 https 块并且它工作了(耶)

<VirtualHost *:80>
  DocumentRoot "/var/www/html/opa/staging/current/app/webroot"

  <Directory /var/www/html/opa/staging/current/app/webroot>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order deny,allow
        Allow from all

        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
   </Directory>

  ServerName opa-staging.capwell.nl
  ServerAlias www.opa-staging.capwell.nl
  Redirect permanent / https://opa-staging.capwell.nl/
  ErrorLog ${APACHE_LOG_DIR}/opa-staging-error.log
  CustomLog ${APACHE_LOG_DIR}/opa-staging-access.log combined
</VirtualHost>

<virtualhost *:443>
  DocumentRoot "/var/www/html/opa/staging/current/app/webroot"

  <Directory /var/www/html/opa/staging/current/app/webroot>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order deny,allow
        Allow from all

        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^ index.php [L]
   </Directory>

  ServerName opa-staging.capwell.nl
  ServerAlias www.opa-staging.capwell.n

  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/certificate.crt
  SSLCertificateKeyFile /etc/apache2/ssl/certificate.key
  SSLCertificateChainFile /etc/apache2/ssl/cabundle.crt
</virtualhost>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-13
    • 2023-04-11
    • 1970-01-01
    • 2015-01-08
    • 1970-01-01
    • 1970-01-01
    • 2012-05-02
    • 2019-12-30
    相关资源
    最近更新 更多