Question about root path for php-fpm
Francis Daly
francis at daoine.org
Fri Mar 20 14:26:27 UTC 2020
On Thu, Mar 19, 2020 at 09:14:15PM +0330, Mahmood Naderan wrote:
Hi there,
> I am following a document but something seems to be a typo and I want to be
> sure about that.
The fragment of the document you have provided seems to duplicate things
unnecessarily; but I do not know what else it tries to do, so maybe it
is correct if you follow it exactly.
>From an nginx/php perspective, the thing that matters is:
* for this particular request, what file on the filesystem do you want
nginx to invite the php-service to process?
If you can make a consistent pattern between url and matching file,
then you can use a configuration that can handle more than one request.
> location ~ \.php$ {
> root /path/to/root (e.g /home/username/htdocs/public_html );
> fastcgi_pass 127.0.0.1:9000;
"root", by itself, is irrelevant to nginx when fastcgi_pass is used.
It only matters if you use a variable (such as $document_root or
$request_filename) that depends on it.
> fastcgi_param SCRIPT_FILENAME $APP_DIR/$fastcgi_script_name; (e.g.,
> /home/username/htdocs/public_html/$fastcgi_script_name)
Usually, "fastcgi_param SCRIPT_FILENAME" names the file that nginx invites
the php service (fastcgi server, php-fpm) to process. In this example,
the only variable it uses is $fastcgi_script_name, which depends on the
url and (maybe) "fastcgi_index". It does not depend on "root".
> include fastcgi_params; }
That file probably includes other variables that might depend on the
"root" setting; whether they are used by your php script being processed
by your php service is a separate question.
> Currently, I have this folder structure
>
> $ ls ~/htdocs/
> build.xml classes controllers etc includes index.html lib
> public_html views
> $ ls ~/htdocs/public_html/index*
> /home/ub/htdocs/public_html/index.php
>
>
> If I open browser and enter localhost, I can see the content of
> ~/htdocs/index.html. So, the first step is fine.
>
>
> The fastcgi_param says $APP_DIR. So, I should write /home/ub/htdocs but the
> "e.g." part says /home/ub/htdocs/public_html
>
> I am not sure if the root in the second step is /home/ub/htdocs or
> /home/ub/htdocs/public_html
> ?
If the request "/one.php" should be handled by the file
"/home/ub/htdocs/public_html/one.php", then you want the "fastcgi_param
SCRIPT_FILENAME" to end up having that filename value.
Often, the directive would be "fastcgi_param SCRIPT_FILENAME
$document_root/$fastcgi_script_name;" or "fastcgi_param
SCRIPT_FILENAME $request_filename;" -- if you use one of those, set
"root /home/ub/htdocs/public_html;". But if you use your own value,
this part of the nginx config does not care about "root".
There is more than one convention for how to match urls to files. The
description you give above suggests that you are mixing different
conventions.
That is perfectly fine; nginx does not care what you do, so long as you
can tell it what you want it to do.
To simplify things, I suggest you put *everything* that you care about
in public_html, and use that as the only "root" set at "server" level
in your nginx config.
But that does depend on what *else* you want this nginx service to do.
Good luck with it,
f
--
Francis Daly francis at daoine.org
More information about the nginx
mailing list