0

question: Is it possible to "add" the contents of a 2nd folder to the current folder file contents? (In essence I was asking from a full Unix is perspective but may be nginx would work too as the goal is for a web server)

Example:

I have /pub where our server software lives. It has index.php But I also have /static/files where test.php lives. I do not want to place test.php in /pub. What I want is that if I visit the nginx webserver with root /pub that it sees both test.php and index.php in the root.

Why?

Because nowadays I have add a lot of validation files to our server that need to exist in the root. Files like bing_dfsfsfsdfs.html and google_aaddasdjsad.html. It is a multiserver setup so the files have amounted to quite a few. I was thinking of creating a folder /static/files where I can store all these single files ... and keep the /pub folder clean with the software only.

5
  • 2
    Can we assume that the user access /pub etc. through a web or FTP server (or similar; please mention which one), or are you dealing with actual directories that users access after logging in with terminal access?
    – Kusalananda
    Apr 12, 2019 at 10:04
  • GNU Stow can be used to symlink the files of one directory into another directory. Apr 12, 2019 at 10:28
  • @JShorthouse That would possibly not help if they are accessing the files through a webserver.
    – Kusalananda
    Apr 12, 2019 at 12:27
  • Updated the question. I was asking for full Unix support but yes the end goal is to do this for a web server running nginx
    – snh_nl
    Apr 12, 2019 at 20:14
  • @snh_nl in the general case, overlayfs on Linux can be used to show the union of contents of two folders. By the way, if my answer worked for you, could you tell us what was the correct config syntax?
    – muru
    Apr 13, 2019 at 4:57

2 Answers 2

0

Purely from an nginx perspective, this seems like a job for try_files. With try_files, you can tell nginx to try multiple locations for a given URI. So something like:

location ~ ^/([^/]+)$ {
  try_files $uri /static/files/$1 =404;
}

I'm not sure of the exact syntax to be used, but the point is to tell nginx to try the default root first for the file, then try in static/files directory in the root and finally return a 404 if nothing worked.

0

you can use alias

http://nginx.org/en/docs/http/ngx_http_core_module.html#alias

Defines a replacement for the specified location.

location ~ ^/(.+\.(?:gif|jpe?g|png))$ {
    alias /static/files/$1;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .