symfony4 - 在 OVH 上部署 Symfony 4 项目
问题描述
我正在尝试在 OVH 上部署使用 Symfony 4 创建的站点。我有两个 .htaccess 文件(一个位于我的代码所在的 www 文件夹的根目录中,另一个位于我的公共文件夹中):
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L] `
在我的公共文件夹中:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
但是当我尝试访问我的网站时出现 404 错误。
有谁知道问题可能来自哪里?
解决方案
OVH 是您的托管服务,它不会向我们提供有关您的服务器配置和安装的任何信息。你使用 Nginx 还是 Apache?PHP FPM 还是 PHP CGI?
由于您使用的是.htaccess
文件,我假设您已经安装了 Apache。
Symfony 有一个安装正确的重写规则以在 Apache 上运行的方法。您可以通过执行以下命令来运行它:
composer require symfony/apache-pack
根据您的 PHP 安装(CGI 或 FPM),在 Apache 上运行 Symfony 有不同的配置。对于 PHP-CGI:
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
所有这些信息都可以在官方文档中找到:Symfony Web Server Configuration
推荐阅读
- concordion - 如何使用junit记录进程md文件?
- php - 在 Add on Domain 中加载 WordPress 文件之外的 WordPress 函数
- flutter - 输入'未来
' 不是类型 '() => void' 的子类型 - django - 如何从forms.ModelForm中渲染表单集[模型使用ForeignKey连接到用户]
- php - Laravel 6:SQLSTATE[HY000]:一般错误:1215 无法添加外键约束
- html - 正则表达式 - 永远挂起
- java - Java android google maps clustering,单击它们后更改标记中的图标
- angular - 下拉菜单不会第二次打开
- spring - 如何使用 SpEL 作为自定义注释的参数
- sinch - 从最近清除应用程序时,Sinch Video clling APi 不起作用