Score:1

need nginx to be able to check directory outside of root directory

jp flag

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.

anx avatar
fr flag
anx
"all sorts of trouble"/"isn't working" could be many things.. please quote some specific log/error
Lazaro Ravelo avatar
jp flag
just added an error that I see is repeated frequently in nginx
Jaromanda X avatar
ru flag
is `client: 192.168.x.x` and `host: "192.168.x.x` the same IP? is that the actual output? did you totally remove some info at `server: ,`?
Lazaro Ravelo avatar
jp flag
@JaromandaX no it's not but they are on the same subnet
Jaromanda X avatar
ru flag
fair enough, not sure why you obfuscated private IP's, or is that the actual output?
Lazaro Ravelo avatar
jp flag
@JaromandaX just obfuscating. Force of habit I guess lol
Jaromanda X avatar
ru flag
[this](https://stackoverflow.com/questions/35261922/how-to-debug-fastcgi-sent-in-stderr-primary-script-unknown-while-reading-respo) and [this](https://serverfault.com/questions/517190/nginx-1-fastcgi-sent-in-stderr-primary-script-unknown) were the frist two results when researching that error - not sure they help, but the answers have a lot of upvotes :p
drmad avatar
gb flag
FYI `try_files $uri $uri/ /index.php?$args;` will try to execute the file `/index.php` if the URL doesn't point to a valid file, which could be messing with the `SCRIPT_FILENAME` value, hence the `Primary script unknown` error.
Lazaro Ravelo avatar
jp flag
@drmad I already had that one in my config
Lazaro Ravelo avatar
jp flag
@JaromandaX I made some changes (updated the original post with the details) and now that error has gone away. What I'm getting now are some jquery related errors. Will update that now.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.