【发布时间】:2021-01-22 21:40:12
【问题描述】:
我需要一些关于在 apache2 Web 服务器上配置 Symfony 的帮助。
我目前的项目类别结构是:
var/www/domain.com/public_html
public_html 内部是我的 Symfony 应用程序所在的位置。
我一直在弄清楚我在 .htaccess 或 /etc/apache2/sites-available/domain.com.conf 文件中做错了什么。
我正在使用 symfony/apache-pack。根据文档,我的 .htaccess 文件位于 /public 文件夹中。这里是:
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
这是我的 /etc/apache2/sites-available/domain.com.conf
<VirtualHost *:80>
ServerAdmin someemail@example.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html/public
<Directory /var/www/mydomain.com/public_html/public>
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
我还阅读了this 并更新了 000-default.conf 如下:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html/public
<Directory /var/www/domain.com/public_html/public>
Options FollowSymlinks MultiViews
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Allow from All
</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 >
</IfModule>
</VirtualHost>
目前我仍然看到 symfony 项目文件夹结构。
我试过了:
- 在 .htaccess 中将 DirectoryIndex 更改为 /public/index.php
- 在 .conf 文件中将 DocumentRoot 更改为 /va/www/domain.com/public_html/public
- 已尝试清除缓存
到目前为止,似乎没有任何帮助。
对任何建议都非常有帮助。
【问题讨论】:
-
DocumentRoot和Directory应该指向.../public_html/public。当你这样做时会发生什么,它如何“无济于事”?您是否看到空白页或...?服务器日志也会很有帮助。 -
@msg,我试过了。将 public 添加到 DocumentRoot 和 Directory,重新启动 apache 并清除缓存。获得相同的 symfony 项目结构
-
相同的结构?使用
src、public等?然后我只能想到两件事:浏览器缓存或您的第二个VirtualHost(您要重定向到的 https 上的那个)仍然配置有public_html。这是what I usually do,只需处理一个VHost配置。 -
@msg,我已经更新了帖子。是的,同样的 symfony 项目结构。浏览器缓存被清除
标签: php apache .htaccess symfony