Serving remote static files with symfony3
The try_files
directive automatically tries to find static files, and serve them as static, prior to giving up, and letting the request be served as a script.
Checks the existence of files in the specified order and uses the first found file for request processing; the processing is performed in the current context. The path to a file is constructed from the file parameter according to the root and alias directives. It is possible to check directory’s existence by specifying a slash at the end of a name, e.g. “$uri/”. If none of the files were found, an internal redirect to the uri specified in the last parameter is made.
Note that although you're already using try_files
, it appears that perhaps your path handling isn't up to spec.
As for your own answer with a temporary solution, there's nothing wrong with using a rewrite or two, but that said, it looks like you'd benefit from the alias
directive.
Defines a replacement for the specified location.
However, you've never explained why you're serving stuff out of /tmp
. Note that /tmp
is often automatically cleared by some cron
scripts, e.g., on OpenBSD, the /etc/daily
script would automatically find
and remove files older than about 7 days (on a daily
basis, as the name suggests).
In summary, you should first figure out what is the appropriate mapping between the web view of the filesystem and your filesystem.
Subsequently, if a prefix is found, just use a separate location
for the assets, together with alias
.
Else, figure out the paths for try_files
to work as intended.
I have find a very ugly solution until anyone find a better solution, here is what I have done :
- I have copied all the assets repository and copied it to my proxy server where nginx is.
Here is my new config :
location /portal/mysite/ { set $frontRoot /srv/data/apps/mysite-portal-stag/current/web; set $sfApp app.php; root /srv/data/apps/mysite-portal-stag/current/web; rewrite ^/portal/mysite/(.*)$ /$1 break; try_files $uri @sfFront;}location /portal/mysite/asset { root /tmp/mysite/asset; rewrite ^/portal/mysite/asset/(.*)$ /$1 break;}location @sfFront { set $frontRootWeb /srv/data/apps/mysite-portal-stag/current/web; root /srv/data/apps/mysite-portal-stag/current/web; fastcgi_pass myAdressWeb:myPort; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $frontRoot/$sfApp; fastcgi_param SCRIPT_NAME /portal/mysite/$sfApp;}
And now it's working, all the js/css and pictures are found.
If anyone think about a "cleaner" answer, he is more than welcome to answer.