Nginx newbie here.
I control the domain eample.com
and the goal is to have three distinct resources available at the following URLs:
example.com
- static landing pageexample.com/siteA
- PHP application Aexample.com/siteB
- PHP application B
I have roughly the following file structure on disk:
/var/www
├── html
│ └── index.html
├── siteA
│ └── index.php
└── siteB
└── public
└── index.php
I have the following (simplified) Nginx configuration
server {
root /var/www/html;
index index.php index.html;
server_name example.com;
# Site A
location /siteA {
#root /var/www/siteA;
alias /var/www/siteA/;
include snippets/fastcgi-php.conf;
}
# Site B
location /siteB/ {
#root /var/www/siteB/public;
alias /var/www/siteB/public/;
include snippets/fastcgi-php.conf;
}
}
The included file snippets/fastcgi-php.conf
contains the following:
location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
try_files $fastcgi_script_name =404;
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
}
The static landing page at example.com
works, but attempting to access example.com/siteA
results in a Primary script unknown
error.
The PHP-FPM
pool access log contains lines like this:
- - 12/Nov/2019:15:57:03 +0200 "GET /siteA/index.php" 404
I believe that the actual file path that PHP-FPM is trying to open is /var/www/html/siteA/index.php
, which is obviously wrong.
I'm pretty sure I'm messing up something related with the root
and/or alias
directives, but I can't quite put my finger on it.
How can I fix my configuration, without altering the disk file structure?
Any pointer would be appreciated.