Всем привет. Текущий конфиг nginx:
server {
listen 80;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /home/app;
location / {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Структура файлов и папок такая - https://prnt.sc/12swbwx
Если обратиться к корню сайта или /index.php получим следующее (логично, так как этого файла не существует):
nginx_1 | 2021/05/11 11:57:47 [error] 31#31: *12 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.21.0.1, server: , request: "GET /index.php HTTP/1.1", upstream: "fastcgi://172.21.0.3:9000", host: "localhost:4443"
php_1 | 172.21.0.2 - 11/May/2021:11:57:47 +0000 "GET /index.php" 404
nginx_1 | 172.21.0.1 - - [11/May/2021:11:57:47 +0000] "GET /index.php HTTP/1.1" 404 27 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0"
nginx_1 | 172.21.0.1 - - [11/May/2021:11:57:47 +0000] "GET /favicon.ico HTTP/1.1" 499 0 "http://localhost:4443/index.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0"
php_1 | 172.21.0.2 - 11/May/2021:11:57:47 +0000 "GET /favicon.ico" 404
Если обратиться к существующему скрипту, получим такой лог:
php_1 | 172.21.0.2 - 11/May/2021:11:58:58 +0000 "GET /init.php" 200
nginx_1 | 172.21.0.1 - - [11/May/2021:11:59:00 +0000] "GET /init.php HTTP/1.1" 200 11 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0"
php_1 | 172.21.0.2 - 11/May/2021:11:59:00 +0000 "GET /favicon.ico" 404
nginx_1 | 2021/05/11 11:59:00 [error] 31#31: *15 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.21.0.1, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "fastcgi://172.21.0.3:9000", host: "localhost:4443", referrer: "http://localhost:4443/init.php"
nginx_1 | 172.21.0.1 - - [11/May/2021:11:59:00 +0000] "GET /favicon.ico HTTP/1.1" 404 27 "http://localhost:4443/init.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0"
Пробовал и такой конфиг:
server {
listen 80;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /home/app;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
При обращении к корню сайта видим то что и хотелось:
nginx_1 | 172.21.0.1 - - [11/May/2021:12:03:55 +0000] "GET / HTTP/1.1" 404 154 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0"
nginx_1 | 172.21.0.1 - - [11/May/2021:12:03:55 +0000] "GET /favicon.ico HTTP/1.1" 404 154 "http://localhost:4443/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0"
Если к /index.php, то:
php_1 | 172.21.0.2 - 11/May/2021:12:04:55 +0000 "GET /index.php" 404
nginx_1 | 2021/05/11 12:04:55 [error] 31#31: *5 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.21.0.1, server: , request: "GET /index.php HTTP/1.1", upstream: "fastcgi://172.21.0.3:9000", host: "localhost:4443"
nginx_1 | 172.21.0.1 - - [11/May/2021:12:04:55 +0000] "GET /index.php HTTP/1.1" 404 27 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0"
К существующему /init.php:
php_1 | 172.21.0.2 - 11/May/2021:12:05:27 +0000 "GET /init.php" 200
nginx_1 | 172.21.0.1 - - [11/May/2021:12:05:28 +0000] "GET /init.php HTTP/1.1" 200 11 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0"
nginx_1 | 172.21.0.1 - - [11/May/2021:12:05:28 +0000] "GET /favicon.ico HTTP/1.1" 404 154 "http://localhost:4443/init.php" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0"