I have a Laravel app that works perfectly fine when running with php artisan serve
but when trying to use nginx as the frontend I'm having all sorts of trouble getting this to work properly.
I basically have this structure:
root@server:/var/www/html# tree -d -L 4
.
`-- app
|-- C4
| `-- www
| |-- sites
| `-- site-assets
`-- prod
|-- app
|-- bootstrap
|-- config
|-- database
|-- public
|-- resources
|-- routes
|-- storage
`-- vendor
Where prod
contains the laravel app
I can get the main app to open but there is a script in prod/public/js
which checks to see if a directory in C4/www/sites/
exists which isn't working and I suspect that my nginx config is the culprit.
Below is my nginx config:
server {
listen 0.0.0.0:80;
listen [::]:80;
root /var/www/html/app/prod/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Disclaimer: I'm not the dev of this app. I'm merely a systems engineer helping out. The devs don't have any experience with nginx
EDIT: adding some errors I'm seeing in /var/log/nginx/error.log
:
2023/02/07 22:25:17 [error] 91535#91535: *23 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.x.x, server: , request: "GET /checksite/domain.com HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php8.1-fpm.sock:", host: "192.168.x.x"
UPDATE: changed the root to /var/www/html/app/prod/public
and the index to just index.php
. The site loads but there's some script that runs which checks for a directory outside of the root to see if it exists and if it doesn't it creates it. What's happening now is that the directory is being created inside the public directory within the laravel app.
UPDATE 2: I'm seeing a jQuery error in the browser console
Uncaught SyntaxError: Unexpected non-whitespace character after JSON at position 2
I will take this up with the devs in the morning to see if they can help debug this.