安装SSL证书后出现太多重定向错误

时间:2019-10-05 09:01:26

标签: php ssl dns apache2 cakephp-1.3

安装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>

1 个答案:

答案 0 :(得分:0)

遵循@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>