My goal is to have a Laravel installation running alongside a Nuxt application generated as static content.
I'd like for Laravel to be available, when the location start with /api
. This works as expected.
For any other requests, I'd like to have Nginx serve me the static content from inside another folder.
I can achieve this by changing the document root at line 18 (root /var/www/html/public/dist;
) and changing the following try_files
configuration to what it states in the config below.
I tried switching root
out for alias
instead, and that gave me some funky results. I get a 500 server response from Nginx with the following output in the error log:
2020/09/29 13:28:17 [error] 7#7: *3 rewrite or internal redirection cycle while internally redirecting to "/index.html", client: 172.21.0.1, server: _, request: "GET /my/fake/url HTTP/1.1", host: "localhost"
172.21.0.1 - - [29/Sep/2020:13:28:17 +0000] "GET /claims/creat HTTP/1.1" 500 580 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36" "-"
I have the following configuration (running inside a Docker container).
server {
listen 80 default_server;
root /var/www/html/public;
index index.html index.htm index.php;
server_name _;
charset utf-8;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }
error_page 404 /index.php;
location / {
alias /var/www/html/public/dist;
try_files $uri $uri/ /index.html;
error_page 404 /400.html;
}
location ~ /api {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I'm not entirely sure what the difference is which also makes me question whether I should use alias
or root
in my case, and I would appreciate some help with understanding this.