Primary script unknown while reading response header from upstream

Viewed 66

I am setting up new laravel project with nginx server configuration ,in sites-available and sites-enabled files i have setup the laravel project details and i added host name in etc/hosts location also,when i hit url(http://hrmcc.test/) in browser i am facing file not found message in browser body,can you please help me to fix this issue

error in log

2022/08/17 13:24:34 [error] 4801#4801: *4 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 127.0.0.1, server: hrmcc.test, request: "GET / HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php7.4-fpm.sock:", host: "hrmcc.test"

sites-available && sites-enabled

server {
listen 80;
server_name hrmcc.test;
root /home/deploy/hrm_v3.2/public;

index index.html index.htm index.php;

charset utf-8;

location / {
try_files $uri $uri/ /index.php?$query_string;
}



location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }

access_log off;
error_log /var/log/nginx/hrmc-error.log error;

sendfile off;

client_max_body_size 100m;

location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}


}

Error in browser

1 Answers

Try to use the default Laravel NGINX configuration.

server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    root /home/deploy/hrm_v3.2/public;
 
    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-Content-Type-Options "nosniff";
 
    index index.php;
 
    charset utf-8;
 
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
 
    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }
 
    error_page 404 /index.php;
 
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }
 
    location ~ /\.(?!well-known).* {
        deny all;
    }
}

This should work. Make sure that your php-fpm socket exists on the location in your configuration. Also make sure to test your configuration by running nginx -t.

Related