Symfony2的生产; Apache的虚拟主机不工作 [英] Symfony2 production; Apache VirtualHost not working

查看:256
本文介绍了Symfony2的生产; Apache的虚拟主机不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新手的Symfony2和MVC框架,但与PHP和Apache的一些经验。

我开发我的工作站上的Apache服务器上的一个项目。我想我们的生产的Ubuntu服务器上部署我的第一个项目的Symfony2也运行Apache。出于某种原因,我无法得到我想要的行为。服务器正在运行多个虚拟主机就好了。但是,试图去当其中的Symfony2项目的的显示,在Symfony2的项目的根I级,而不是得到的目录内容的列表(虽然虚拟主机是指向/ WEB子目录)。如果我手动导航到web目录,我可以使用项目时,而没有给pretty得到在任一app_dev.php或app.php前端控制器项目的点击,不过app.php和app_dev.php坚持网址(用FC隐藏)。

我搜索解决方案和使用./app/console --env = PROD缓存尝试:明确无济于事。 Apache的mod_rewrite启用,并且默认的Symfony2的.htaccess文件应该被处理重写即使我的虚拟主机是不是(这将是preferred)。

感谢您的帮助!

主要虚拟主机:

 <虚拟主机*:80>
    服务器名server.com
    ServerAlias​​ www.server.com
    的ServerAdmin webmaster@server.com    的DocumentRoot的/ var / WWW /主/公    <目录/ var / WWW /主/公>
        所有的AllowOverride
        为了允许,拒绝
        所有允许
        多视图选项了FollowSymLinks索引IncludesNoExec
    < /目录>    <位置/>
        #主网站中,使用此Zend框架完成。
        SETENV APPLICATION_ENV生产
        RewriteEngine叙述在
        的RewriteCond%{} REQUEST_FILENAME -s [OR]
        的RewriteCond%{} REQUEST_FILENAME -l [OR]
        的RewriteCond%{} REQUEST_FILENAME -d
        。重写规则^ * $ - [NC,L]
        重写规则^ * $的index.php [NC,L]
    < /地点>    错误日志/var/log/apache2/error-main.log
    LogLevel的错误    的CustomLog /var/log/apache2/access-main.log结合
    ServerSignature在    别名/项目/无功/网络/项目/网络< /虚拟主机>

项目虚拟主机:

 <虚拟主机*:80>    的DocumentRoot的/ var / WWW /项目/网络
    别名/项目/无功/网络/项目/网络    <目录/ var / WWW /项目/网络/>
        选择指数多视图了FollowSymLinks
        所有的AllowOverride
        为了允许,拒绝
        所有允许        DirectoryIndex的app.php    < /目录>    错误日志$ {} APACHE_LOG_DIR /error-project.log    #可能的值包括:调试,信息,通知,警告,错误,暴击,
    #警报,EMERG。
    LogLevel的信息    的CustomLog $ {} APACHE_LOG_DIR结合/access-project.log< /虚拟主机>

使用项目/网页默认的.htaccess文件/

 #使用前端控制器作为索引文件。它作为备用解决方案时,
#每隔重写/重定向失败(在别名环境例如不
#mod_rewrite的)。此外,这减少了匹配过程
#起始页(路径/),否则Apache将适用rewritting规则
#到每个配置文件的DirectoryIndex(例如的index.php,index.html的,index.pl)。
DirectoryIndex的app.php< IfModule mod_rewrite.c>
    RewriteEngine叙述在    #重定向到URI没有前端控制器prevent重复的内容
    #(有和没有`/ app.php`)。只有做到这一点重定向初始
    由Apache和没有随后的周期#重写。否则,我们将得到一个
    #无尽的重定向循环(要求 - >改写为前端控制器 - >
    #重定向 - >要求 - > ...)。
    #所以,如果你得到一个过多的重定向的错误,或者你总是被重定向
    #到起始页,因为你的Apache不公开RED​​IRECT_STATUS
    #环境变量,你有两个选择:
    # - 通过注释下面两行禁用此功能或
    # - 使用Apache> = 2.3.9和结束标志全部更换l标志并删除
    #以下的RewriteCond(最佳解决方案)
    的RewriteCond%{ENV:REDIRECT_STATUS} ^ $
    重写规则^应用\\的.php(/(.*)| $)%{CONTEXT_ preFIX} / $ 2 [R = 301,L]    #如果请求的文件存在,只是为它服务。
    #我们只想让Apache处理文件,而不是目录。
    的RewriteCond%{} REQUEST_FILENAME -f
    重写规则? - [L]    #下面重写所有其他查询到前端控制器。该
    #条件保证,如果你使用的是Apache别名做群众虚拟
    #托管,基本路径将是prepended允许的妥善解决
    #app.php文件;它会在不走样的环境中工作,以及提供
    #一个安全,一个一刀切的解决方案。
    的RewriteCond%{REQUEST_URI} :: $ 1 ^(/.+)(+):: \\ $ 2
    重写规则^(。*) - [E = BASE:%1]
    重写规则? %{ENV:BASE} app.php [L]
< / IfModule><!IfModule mod_rewrite.c>
    < IfModule mod_alias.c>
        #当mod_rewrite的不可用,我们指示的临时重定向
        #的起始页到前端控制器明确,以便网站
        #和产生的链路仍然可以使用。
        RedirectMatch 302 ^ / $ /app.php/
        #RedirectTemp不能用来代替
    < / IfModule>
< / IfModule>


解决方案

您ServerName指令是错误的。应该只有站在一个领域,在此之后的路径。决不。如果你想在/项目在你的SF项目必须在原有server.com文件的虚拟主机使用的别名。

 <虚拟主机*:80>
    服务器名server.com
    站长的ServerAdmin @本地    DocumentRoot的/var/www/other-server.com-stuff
    <目录/var/www/other-server.com-stuff>
        #工具和其他的东西
    < /目录>    别名/项目/无功/网络/项目/网络
    <目录/ var / WWW /项目/网络/>
        选择指数多视图了FollowSymLinks
        所有的AllowOverride
        为了允许,拒绝
        所有允许
    < /目录>    错误日志$ {} APACHE_LOG_DIR /error.log    #可能的值包括:调试,信息,通知,警告,错误,暴击,
    #警报,EMERG。
    LogLevel的信息    的CustomLog $ {} APACHE_LOG_DIR结合/access.log< /虚拟主机>

如果你只想要顺丰项目,只要正确地更改了服务器名称。

I'm a novice to Symfony2 and MVC frameworks but have some experience with PHP and Apache.

I developed a project on an Apache server on my workstation. I'm trying to deploy my first Symfony2 project on our production Ubuntu server, also running Apache. For some reason I cannot get the behavior I want. The server is running multiple virtual hosts just fine. However, when attempting to go to where the Symfony2 project should show up, I instead get a listing of the directory contents at the root level of the Symfony2 project (though the vhost is pointing to the /web subdirectory). If I manually navigate to the web directory I can get to the project clicking on either the app_dev.php or app.php front controllers, however app.php and app_dev.php persist when using the project instead of giving "pretty" URLs (with the fc hidden).

I've searched for solutions and tried using ./app/console --env=prod cache:clear to no avail. Apache mod_rewrite is enabled, and the Symfony2 default .htaccess file should be handling rewrites even if my vhost isn't (which would be preferred).

Thank you for any help!

Main vhost:

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

Project 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>

Using the default .htaccess file in project/web/

# 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>

解决方案

Your ServerName directive is wrong. There should only stand a domain, no path afterwards. NEVER. If you want your sf project under the /project you have to use an alias in the VHost of the original server.com file.

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

if you want only the sf project, simply change the ServerName correctly.

这篇关于Symfony2的生产; Apache的虚拟主机不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆