The url of a symfony application running behind a reverse proxy

I will try to explain the scenario as best I can as it seems a little complicated.

I am building this web application for a large organization that has many other web applications running on their servers. When I finally finished the development phase, they asked me to send them a virtual machine with everything configured and ready to run (web app, apache, database, etc.), and also with some magic that is unknown for me (they were talking about reverse proxy), they would make it available to the whole world.

So I sent them a car and they put it online at http://www.fakedomain.com/fakedirectory (of course / fakedirectory)

Now this actually redirects external requests to the web server running in my virtual machine. The problem is that my symfony application generates all of my urls relative to the webserver in a virtual machine that runs on a root ("/") basis. But the actual url that users are accessing is / fakedirectory. So, for example, this is what you get when you access /fakedirectory/doc.html:

<html>
...
<body>
    ...
    <a href="/anotherdoc.html">A link</a>
</body>
</html>

      

If the user clicks "Link" it will result in a 404 error because the actual url should be /fakedirectory/anotherdoc.html

The way I see it, it must have something to do with the specified reverse proxy that communicates with the VM. But my client organization's IT department suggested that it would be easier if my symfony application just spun the URL.

So, before I (possibly mistakenly) ask IT to do something in my proxy, is there a way I can access this in my VM? I read about the symfonys doc about request context , specifically:

# app/config/parameters.yml
parameters:
    router.request_context.host: www.fakedomain.com
    router.request_context.scheme: http
    router.request_context.base_url: fakedirectory

      

But this doesn't seem to apply globally to the entire symfony url system. I have also tried some strange configurations in apache mod_proxy and mod_rewrite with no luck.

So, in short, I have absolutely no idea, so any thoughts would be appreciated. Thanks in advance.

+3


source to share


2 answers


I faced a similar problem. In this case, url Rewrites will not help because symfony gets the base path from variables $_SERVER

based on the location of the app.PHP script. REQUEST_URI

will be /fakedirectory/

, but SCRIPT_NAME

will be /app.php

, so the base path becomes /

, and is fakedirectory

treated as, the path to the symfony router.

DECISION:



Make a symbolic link to fakedirectory. Inside the web directory, run ln -s . fakedirectory

.

Now with REQUEST_URI

how /fakedirectory/

you will have a SCRITP_NAME

value equal /fakedirectory/app.php

, and all paths to resources or routers will have the correct base path /fakedirectory/

.

+1


source


I think you can solve this using the RewriteBase rule?



<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /fakedirectory/web
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ app.php [QSA,L] 
</IfModule>

      

+1


source







All Articles