Symfony4 routing inside a subfolder

前端 未结 2 703
闹比i
闹比i 2020-12-22 10:00

I have a symfony app in my /var/www/html/app/ and I\'d like to access it via host/app/ but I can\'t make it work.

I have a conf fil         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-22 10:02

    The problem is the that your web server's document root (the directory that apache will make public via the url) and your project's document root (the public directory) are not the same. Instead your server points to the project directory. That is why you have to manually go into the project's document root by adding the public/ to the url.

    You should avoid making the project directory accessible as this could expose your configuration and thus make your website vulnerable, e.g. by giving people access to your database through the credentials inside the config.

    You might be able to achieve your goal by storing the project somewhere else and then only symlink your project's public dir to /var/www/html/app. This will probably require some changes to your apache config, e.g. adding Options FollowSymLinks.

    Another, more elaborate, approach could be using mod_proxy. The configuration will roughly look like this:

    # Your public server reachable from the outside
    
        ProxyPass /app http://127.0.0.1:8080/
    
    
    # Your internal server where the requests are proxied to
    
        
            AllowOverride All
            Order Allow,Deny
    
            Allow from All
        
        ...
    
    

    As you can see the internal web server points to your project's document root (public dir). You might have to do additional both in the apache setup and app, e.g. make sure trusted proxies are set correctly or adding ProxyPreserveHost On to the apache setup, but roughly this should point you in the right direction.

    edit: I missed another obvious solution, using mod_alias to point your symfony app to /app:

    Alias /app /var/www/html/app/public
    

提交回复
热议问题