Symfony2生产;Apache VirtualHost不工作
我是Symfony2和MVC框架的新手,但对PHP和Apache有一些经验 我在工作站上的Apache服务器上开发了一个项目。我正试图将我的第一个Symfony2项目部署到我们的Ubuntu生产服务器上,该服务器也运行Apache。由于某种原因,我无法得到我想要的行为。服务器正在运行多个虚拟主机,一切正常。但是,当尝试转到Symfony2项目应该显示的位置时,我得到了Symfony2项目根级别的目录内容列表(尽管vhost指向/web子目录)。如果我手动导航到web目录,我可以点击app_dev.php或app.php前端控制器进入项目,但是app.php和app_dev.php在使用项目时会保持不变,而不是给出“漂亮”的URL(隐藏fc) 我搜索了解决方案并尝试使用./app/console--env=prod cache:clear无效。Apache mod_rewrite已启用,即使vhost未启用,Symfony2 default.htaccess文件也应处理重写(这是首选) 谢谢你的帮助 主要虚拟主机:Symfony2生产;Apache VirtualHost不工作,apache,symfony,deployment,url-routing,virtualhost,Apache,Symfony,Deployment,Url Routing,Virtualhost,我是Symfony2和MVC框架的新手,但对PHP和Apache有一些经验 我在工作站上的Apache服务器上开发了一个项目。我正试图将我的第一个Symfony2项目部署到我们的Ubuntu生产服务器上,该服务器也运行Apache。由于某种原因,我无法得到我想要的行为。服务器正在运行多个虚拟主机,一切正常。但是,当尝试转到Symfony2项目应该显示的位置时,我得到了Symfony2项目根级别的目录内容列表(尽管vhost指向/web子目录)。如果我手动导航到web目录,我可以点击app_dev
<VirtualHost *:80>
ServerName server.com
ServerAlias www.server.com
ServerAdmin webmaster@server.com
DocumentRoot /var/www/main/public
<Directory /var/www/main/public>
AllowOverride all
Order allow,deny
Allow from all
Options MultiViews Indexes FollowSymlinks IncludesNoExec
</Directory>
<Location />
# The main site was done in Zend Framework which uses this.
SetEnv APPLICATION_ENV "production"
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</Location>
ErrorLog /var/log/apache2/error-main.log
LogLevel error
CustomLog /var/log/apache2/access-main.log combined
ServerSignature On
Alias /project /var/www/project/web
</VirtualHost>
ServerName服务器.com
服务器别名www.server.com
服务器管理员webmaster@server.com
DocumentRoot/var/www/main/public
允许超越所有
命令允许,拒绝
通融
选项多视图索引以下符号链接包括noexec
#主站点是在Zend框架中完成的,Zend框架使用了此功能。
SetEnv应用程序_ENV“生产”
重新启动发动机
RewriteCond%{REQUEST_FILENAME}-s[或]
RewriteCond%{REQUEST_FILENAME}-l[或]
RewriteCond%{REQUEST_FILENAME}-d
重写规则^.*$-[NC,L]
重写规则^.*$index.php[NC,L]
ErrorLog/var/log/apache2/error-main.log
日志级错误
CustomLog/var/log/apache2/access-main.log组合
服务器签名
别名/project/var/www/project/web
项目vhost:
<VirtualHost *:80>
DocumentRoot /var/www/project/web
Alias /project /var/www/project/web
<Directory /var/www/project/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
DirectoryIndex app.php
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error-project.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access-project.log combined
</VirtualHost>
DocumentRoot/var/www/project/web
别名/project/var/www/project/web
选项索引跟随符号链接多视图
允许超越所有
命令允许,拒绝
通融
DirectoryIndex app.php
ErrorLog${APACHE_LOG_DIR}/error-project.LOG
#可能的值包括:调试、信息、通知、警告、错误、临界值、,
#警惕,埃默格。
日志级别信息
CustomLog${APACHE_LOG_DIR}/access-project.LOG组合
在project/web中使用默认的.htaccess文件/
# Use the front controller as index file. It serves as fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# startpage (path "/") because otherwise Apache will apply the rewritting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect to URI without front controller to prevent duplicate content
# (with and without `/app.php`). Only do this redirect on the initial
# rewrite by Apache and not on subsequent cycles. Otherwise we would get an
# endless redirect loop (request -> rewrite to front controller ->
# redirect -> request -> ...).
# So in case you get a "too many redirects" error or you always get redirected
# to the startpage because your Apache does not expose the REDIRECT_STATUS
# environment variable, you have 2 choices:
# - disable this feature by commenting the following 2 lines or
# - use Apache >= 2.3.9 and replace all L flags by END flags and remove the
# following RewriteCond (best solution)
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{CONTEXT_PREFIX}/$2 [R=301,L]
# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# The following rewrites all other queries to the front controller. The
# condition ensures that if you are using Apache aliases to do mass virtual
# hosting, the base path will be prepended to allow proper resolution of the
# app.php file; it will work in non-aliased environments as well, providing
# a safe, one-size fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule .? %{ENV:BASE}app.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
# When mod_rewrite is not available, we instruct a temporary redirect of
# the startpage to the front controller explicitly so that the website
# and the generated links can still be used.
RedirectMatch 302 ^/$ /app.php/
# RedirectTemp cannot be used instead
</IfModule>
</IfModule>
#将前控制器用作索引文件。当发生以下情况时,它可作为后备解决方案:
#每隔一次重写/重定向都会失败(例如,在没有
#修改(重写)。此外,这还减少了对象的匹配过程
#startpage(路径“/”),否则Apache将应用重写规则
#到每个配置的DirectoryIndex文件(例如index.php、index.html、index.pl)。
DirectoryIndex app.php
重新启动发动机
#重定向到不带前端控制器的URI以防止重复内容
#(带或不带“/app.php”)。仅在初始路径上执行此重定向
#由Apache重写,而不是在后续周期中重写。否则我们会被解雇
#无休止的重定向循环(请求->重写到前端控制器->
#重定向->请求->…)。
#所以,如果你得到一个“太多重定向”错误或你总是得到重定向
#因为您的Apache没有公开重定向的状态
#环境变量,您有两种选择:
#-通过注释以下两行或两行禁用此功能
#-使用Apache>=2.3.9,用结束标志替换所有L标志,并删除
#第二步(最佳解决方案)
RewriteCond%{ENV:REDIRECT_STATUS}^$
重写规则^app\.php(/(.*)|$)%{CONTEXT_PREFIX}/$2[R=301,L]
#如果请求的文件名存在,只需提供它即可。
#我们只想让Apache服务于文件,而不是目录。
RewriteCond%{REQUEST_FILENAME}-f
重写规则[L]
#下面将所有其他查询重写到前端控制器。这个
#条件确保,如果您使用Apache别名进行大规模虚拟
#宿主时,将预先设置基本路径,以允许正确解析
#php文件;它也可以在无别名的环境中工作,提供
#一个安全、一刀切的解决方案。
RewriteCond%{REQUEST_URI}:$1^(/.+)(.+):\2$
重写规则^(.*)-[E=基:%1]
重写规则.?%{ENV:BASE}app.php[L]
#当mod_rewrite不可用时,我们指示临时重定向
#将起始页显式地发送到前端控制器,以便网站
#生成的链接仍然可以使用。
重定向匹配302^/$/app.php/
#不能改为使用RedirectTemp
您的ServerName指令错误。应该只有一个域,之后没有路径。从未。如果希望sf项目位于/project下,则必须在原始server.com文件的VHost中使用别名
<VirtualHost *:80>
ServerName server.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/other-server.com-stuff
<Directory /var/www/other-server.com-stuff>
# stuff for other stuff
</Directory>
Alias /project /var/www/project/web
<Directory /var/www/project/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel info
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
ServerName服务器.com
服务器管理员webmaster@localhost
DocumentRoot/var/www/other-server.com-stuff
#以物换物
别名/project/var/www/project/web
选项索引跟随符号链接多视图
允许超越所有
命令允许,拒绝
通融
ErrorLog${APACHE_LOG_DIR}/error.LOG
#可能的值包括:调试、信息、通知、警告、错误、临界值、,
#警惕,埃默格。
日志级别信息
CustomLog${APACHE\u LOG\u DIR}/access.LOG组合
如果您只想要sf项目,只需正确更改服务器名即可。除了您应该投票支持的s之外,您还应该注意以下几点:
为了获得干净的URL,您需要指定虚拟主机的目录索引:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
RedirectMatch permanent ^/app_dev\.php/(.*) /$1
DocumentRoot /var/www/project/web
节点指出,更改项目的.htaccess不是一个好做法,bu
DocumentRoot /var/www/project/web