php not working from aliased subdir

Francis Daly francis at
Thu Feb 2 08:20:15 UTC 2017

On Wed, Feb 01, 2017 at 06:53:23PM +0200, Nikolaos Milas wrote:
> On 31/1/2017 10:13 μμ, Francis Daly wrote:

Hi there,

Good that you got it working for you.

> By the way, is there some method to define a block of code which can
> be included at various places?

In stock nginx.conf? Not, not as as block.

In general, you can store it in a separate file and "include" it.

Or in general, you can use your favourite macro processor and write your
own pre-nginx.conf file which does whatever substitution you want to
create your active nginx.conf.

But in this specific case...

>         location ~ \.php$ {
>            fastcgi_param SCRIPT_FILENAME $request_filename;
>            fastcgi_param QUERY_STRING    $query_string;
>            fastcgi_param REQUEST_METHOD  $request_method;
>            fastcgi_param CONTENT_TYPE    $content_type;
>            fastcgi_param CONTENT_LENGTH  $content_length;

All of those things could probably go into your /etc/nginx/fastcgi_params,
which you include anyway below.

>            fastcgi_pass unix:/tmp/php-fpm.sock;

That should stay within the location.

>            fastcgi_index index.php;

That can be removed, as it does nothing useful here. (It says: if the
request ends in /, then use the index.php file. But it is in a location{}
where the request must end in p.)

>            include /etc/nginx/fastcgi_params;
>         }

In fact, you could possibly have all of the fastcgi_param stuff written
once, at server{} level, so that your repeated content is just

  location ~ \.php$ {
    fastcgi_pass unix:/tmp/php-fpm.sock;

with maybe an "include /etc/nginx/fastcgi_params;" in there too.

> Can we define it as a block and include it where needed as a reference?

By the time it is 3 or 4 lines, (or just 1, since the newlines above
are optional) it is possibly worth just copying the content instead of
copying an "include" line.

It's not the (general) answer that you want, but it might be enough
for now.


Francis Daly        francis at

More information about the nginx mailing list