I will not display the entire file. Everything works in this file except the handling of the /client location, which I setup below:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
location /client {
alias /var/www/client/dist;
try_files $uri $uri/ /var/www/client/dist/index.html =404;
}
I am serving a php application from the /var/www/server
directory. It properly operates at this time.
From the /var/www/client
directory, I have made an Angular2 application. The command ng build --prod --base-href=/client/
builds the application and stores it in the folder /var/www/client/dist/
, which has the index file located at /var/www/client/dist/index.html
.
A request for a file that exists at /var/www/client/dist/real_file_path.ext
should be made to http://host/client/real_file_path.ext
, and a request for a file that does not exist, such as http://host/client/non-existant/directory
should be directed to /var/www/client/dist/index.html
where the application parses the url to route the view and controler.
The log shows that the alias successfully redirects requests from /client
to /client/dist
, but it serves a 404
instead of serving /var/www/client/dist/index.html
.
What is causing the failure?
I clearly don't understand something about alias or try_files.
I have tried using:
try_files $uri $uri/ /client/dist/index.html =404;
This did not correct the issue either.
After each change, I run sudo nginx -s reload
.
After each change, I verify the performance of the php application.