Symfony base url proxypass

时间:2018-04-10 11:21:53

标签: apache symfony assets proxypass

我的symfony网站是代理通行证的背后,这是我的代理通行证:

<VirtualHost *:80>
    ServerName mydomain.dev
    ProxyPreserveHost on

    # setup the proxy
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass /foo http://10.0.3.22/foo
    ProxyPassReverse /foo http://10.0.3.22/foo

</VirtualHost>

因为mydomain.dev是另一个网站。

当我打开http://mydomain.dev/foo时,我的symfony网站呈现但所有资产都返回404 Not Found,因为它尝试从网址http://mydomain.dev/css/获取...而不是http://mydomain.dev/foo/css/ ...

如果我从proxypass中删除/ foo,也会遇到同样的问题:

ProxyPass /foo http://10.0.3.22/
ProxyPassReverse /foo http://10.0.3.22/

我希望我的symfony中的所有资产,所有路由和所有链接都以/ foo为前缀,是否有任何配置? Symfony或Apache配置?

由于

-

Symfony 2.5.6 | Apache 2.4

1 个答案:

答案 0 :(得分:0)

自答案:

参数

我在参数中添加了前缀:

#parameters.yml
parameters:
  website_prefix: foo

路由

并为我的所有路线添加了前缀,如下所示:

#app/config/routing_base.yml
twig:
    globals:
        asset_base: "/%website_prefix%"
login:
    path:   /login
    defaults:  { _controller: 
    ezpublish.security.controller:loginAction }
login_check:
    path:   /login_check
logout:
    path:   /logout

_ezpublishRoutes:
    resource: "@EzPublishCoreBundle/Resources/config/routing/internal.yml"

_ezpublishLegacyRoutes:
    resource: "@EzPublishLegacyBundle/Resources/config/routing.yml"

_ezpublishRestRoutes:
    resource: "@EzPublishRestBundle/Resources/config/routing.yml"
    prefix:   %ezpublish_rest.path_prefix%

_ezpublishRestOptionsRoutes:
    resource: "@EzPublishRestBundle/Resources/config/routing.yml"
    prefix: %ezpublish_rest.path_prefix%
    type: rest_options

_liip_imagine:
    resource: "@LiipImagineBundle/Resources/config/routing.xml"

#_ezpublishDemoRoutes:
#    resource: "@eZDemoBundle/Resources/config/routing.yml"

#app/config/routing.yml
_routing_prefixed:
    resource: "routing_base.yml"
    prefix:   %website_prefix%

资产

对于我的资产,我使用了一个树枝全局变量:

#app/config/config.yml
twig:
    globals:
        assets_base: "%website_prefix%"

在我的树枝上

{% stylesheets filter='?yui_css, cssrewrite' output='css/main.css'
        'bundles/mybundle/css/bootstrap.css'
        'bundles/mybundle/css/cs-select.css'
        'bundles/mybundle/css/cs-skin-border.css'
        'bundles/mybundle/css/video-js.css'
        'bundles/mybundle/css/owl.carousel.css'
        'bundles/mybundle/css/owl.theme.css'
        'bundles/mybundle/css/main.css'
        'bundles/mybundle/css/custom.css'
    %}
        <link href="{{ assets_base }}/{{ asset_url }}" rel="stylesheet">
    {% endstylesheets %}

它运作良好:)