symfony - 如何在 Apache 虚拟主机中使用 ssl 证书 (https) 在 cpanel 托管中配置 Symfony 应用程序

标签 symfony ssl https cpanel

这是我的场景:

  1. 我的 Symfony 3.3 应用程序部署在我的域中,在 Godaddy 的专用主机中使用 cpanel。
  2. 我的文档根目录不是public_html,它是public_html 中的一个子文件夹
  3. 通过http我可以正常访问我的网站
  4. 当我在 cpanel 中成功安装 ssl 证书然后更新 web 文件夹下的 .htaccess 以重定向到 https 时,站点被重定向到 public_html 文件夹,而不是 public_html/subfolder/web,就像 http 一样通常。

请问有人能帮我解决这个问题吗?

我希望将我的 Symfony web 文件夹更改为 public_html 文件夹不是唯一的解决方案。

更新 1

我的 .htaccess 文件

DirectoryIndex app.php
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
    RewriteEngine On
    # start https
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    # end https
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]
    RewriteRule ^ %{ENV:BASE}/app.php [L]
</IfModule>

<IfModule !mod_rewrite.c>
    <IfModule mod_alias.c>
        RedirectMatch 302 ^/$ /app.php/
    </IfModule>
</IfModule>

更新 2

我找到了问题和解决方案,这就是我更改问题标题的原因,因为问题不在于 Symfony,而在于 Apache 虚拟主机配置。

最佳答案

您可以使用安全配置来解决这个问题。这是一个例子 https://symfony.com/doc/current/security/force_https.html

或路由

https://symfony.com/doc/current/routing/scheme.html

关于symfony - 如何在 Apache 虚拟主机中使用 ssl 证书 (https) 在 cpanel 托管中配置 Symfony 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48669449/

相关文章:

php - 将 kernel.root_dir 注入(inject) Symfony2 中的实体构造函数

php - Symfony 2 Assets 过滤器异常中的 compass

ssl - 允许 mutating webhook 与启用 tls 的 istio 一起工作

JavaScript HTTPS 到 HTTP iFrame 安全问题

iphone - 如何在iPhone模拟器中使用不受信任的服务器证书向主机发送HTTPS请求?

node.js - 如何使用 Nginx 在 MEAN 堆栈应用程序上正确设置 HTTPS/SSL

php - Symfony 按实体获取数据库表数据

.htaccess - AllowOverride all 导致错误 403

ssl - 为 SSH 生成 SSL key 对时,您可以使用的最大位数 (-b) 是多少?

ssl - x509 证书如何知道链接到私钥?