-
Notifications
You must be signed in to change notification settings - Fork 251
Nginx subdir
Mark Friedrich edited this page Nov 17, 2018
·
8 revisions
In case you want to install Pathfinder in a subdirectory https://www.[DOMAIN].com/subdir
rather than on a TLD https://www.[DOMAIN].com
, you need to adjust your Nginx config and *.ini files.
- Add subdir name
/subdir
toBASE
property. -
URL
still points to the TLD.
BASE = /subdir
URL = {{@SCHEME}}://local.pathfinder
Here are the required adjustments need to be done in your existing pathfinder.conf
file: wiki: pathfinder.conf
Info: Read this article for a more detailed information how it works.
- No changes made to default
location / {..}
section. (no longer used by Pathfinder) - New
location /subdir {..}
section points tohttps://www.[DOMAIN].com/subdir
URL -
alias
points to your Pathfinder project directory (change this to your project directory) - First trick:
try_files
checks the existence of the requested URL against a named locationlocation @subdir {..}
-
location @subdir {..}
rewrites any incoming request (e.g./subdir/setup
or/subdir/img/1.jpg
) to/subdir/index.php
by searching for a new location matching the changed URI (see flag:last
). - New rewrite URL
/subdir/index.php
matcheslocation ~ \.php$ {..}
inside thelocation /subdir {..}
block -
SCRIPT_FILENAME $request_filename
is important. This changes file path for the current request, based on the alias directive, and the request URI:/subdir/index.php
becomesindex.php
. Pathfinder´s URL rooting engine expectsindex.php
asSCRIPT_FILENAME
, otherwise internal root aliases can not be matched against an incoming request. - The default
location ~ \.php$ {..}
is no longer used by Pathfinder (maybe by an other app on your server) andSCRIPT_FILENAME
is still set to$document_root$fastcgi_script_name
(default).
Hint: GET parameters don´t get lost during rewrite.
server {
listen [::]:443 ssl http2;
listen 443 ssl http2 backlog=16384 reuseport;
server_name www.pathfinder-w.space;
root /var/www;
location / { ## [1]
index index.php;
try_files $uri $uri/ /index.php?$query_string;
}
location /subdir { ## [2]
alias /var/www/pathfinder-w.space/public_html; ## [3]
try_files $uri $uri/ @subdir; ## [4]
location ~ \.php$ { ## [6]
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename; ## [7]
include fastcgi_params;
}
}
location @subdir {
rewrite /subdir/(.*)$ /subdir/index.php last; ## [5]
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; ## [8]
include fastcgi_params;
}
}