【发布时间】:2022-01-03 17:32:20
【问题描述】:
我们有一个 Magento 2 网站。由于某种原因,我们的 Nginx/PHP-FPM 无法从 MAGEROOT/pub/ 文件夹中读取文件,而不是 index.php。
我们在 Nginx 日志 "Unable to open primary script: /home/goodprice/public_html/releases/current/pub/get.php (No such file or directory)" 中收到以下错误,并且浏览器显示 No input file specified.
这是部分 Nginx 配置文件。
# Run Magento (behind Varnish)
server {
listen 8088;
server_name {{website name}}.com.au www.{{website name}}.com.au m2.{{website name}}.com.au;
set $MAGE_ROOT /home/goodprice/public_html/releases/current;
index index.php;
root $MAGE_ROOT/pub;
set $code default;
location /sitemap.xml {
root $MAGE_ROOT/pub/media;
autoindex off;
}
# Rewrites for edm
include /etc/nginx/global/rewrites.conf;
location / {
try_files $uri $uri/ /index.php?$args;
}
# Serve media under /pub/media/
location /pub/ {
location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
deny all;
}
alias $MAGE_ROOT/pub/;
add_header X-Frame-Options "SAMEORIGIN";
}
# Rewrite signed static files
rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
# Static assets
location ~ ^/static/(version\d*/)?(.*)$ {
tcp_nodelay on;
# Images, CSS, JS
location ~* \.(jpg|jpeg|png|gif|svg|js|css|ico|txt)$ {
expires max;
log_not_found off;
access_log off;
add_header ETag "";
add_header Access-Control-Allow-Origin "*";
add_header Cache-Control "public";
try_files $uri $uri/ @static;
}
# Fonts
location ~* \.(swf|eot|ttf|otf|woff|woff2)$ {
expires max;
log_not_found off;
access_log off;
add_header ETag "";
add_header Access-Control-Allow-Origin "*";
add_header Cache-Control "public";
try_files $uri $uri/ @static;
}
# Catch all
try_files $uri $uri/ @static;
}
# Media assets
location /media/ {
tcp_nodelay on;
autoindex off;
# Images, CSS, JS
location ~* \.(jpg|jpeg|png|gif|svg|js|css|ico|txt)$ {
expires max;
log_not_found off;
access_log off;
add_header ETag "";
add_header Access-Control-Allow-Origin "*";
add_header Cache-Control "public";
try_files $uri $uri/ @media;
}
# Fonts
location ~* \.(swf|eot|ttf|otf|woff|woff2)$ {
expires max;
log_not_found off;
access_log off;
add_header ETag "";
add_header Access-Control-Allow-Origin "*";
add_header Cache-Control "public";
try_files $uri $uri/ @media;
}
# Catch all
try_files $uri $uri/ @media;
}
# Password paths
location /media/order_attachments {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
}
location /media/convert {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
}
# Below prescriptions dir does not contain actual prescriptions
#location /media/prescriptions {
# auth_basic "Restricted";
# auth_basic_user_file /etc/nginx/htpasswd;
#}
location /media/webforms {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
}
location /media/raveinfosys/exporter {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/htpasswd;
}
location @static { rewrite /static/(version\d*/)?(.*)$ /static.php?resource=$2 last; }
location @media { try_files $uri $uri/ /get.php$is_args$args; }
# PHP entry point for setup application
location ~* ^/setup($|/) {
root $MAGE_ROOT;
location ~ ^/setup/index.php {
fastcgi_pass fastcgi_backend;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=600";
fastcgi_read_timeout 300s;
fastcgi_connect_timeout 300s;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/setup/(?!pub/). {
deny all;
}
location ~ ^/setup/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
}
# PHP entry point for update application
location ~* ^/update($|/) {
root $MAGE_ROOT;
location ~ ^/update/index.php {
fastcgi_split_path_info ^(/update/index.php)(/.+)$;
fastcgi_pass fastcgi_backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
# Deny everything but index.php
location ~ ^/update/(?!pub/). {
deny all;
}
location ~ ^/update/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
}
# Main PHP
location ~ (index|get|static|report|404|503|health_check|deploy_clear_opcache)\.php$ {
try_files $uri =404;
fastcgi_pass fastcgi_backend;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_read_timeout 300s;
fastcgi_connect_timeout 300s;
# fastcgi_param MAGE_MODE $MAGE_MODE;
fastcgi_param MAGE_RUN_CODE $code;
fastcgi_param MAGE_RUN_TYPE store;
# Increase fastcgi buffer size to stop nginx errors on large posts
fastcgi_buffers 32 256k;
fastcgi_buffer_size 512k;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_hide_header 'X-Powered-By';
}
# Return 503 if the maintenance flag is found
# if (-f $MAGE_ROOT/var/.maintenance.flag) {
# return 503;
# }
#
# # Custom 503 error page
# error_page 503 @maintenance;
#
# location @maintenance {
# root /home/goodprice/public_html/maintenance;
# rewrite ^(.*)$ /503.html break;
# }
# Use Magento 403 404 page
error_page 403 404 /errors/404.php;
# Banned locations (only reached if the earlier PHP entry point regexes don't match)
location ~* (\.php$|\.htaccess$|\.git) {
deny all;
}
}
这会导致一些问题。一是 Magento 2 无法提供占位符图像,因为它需要执行 get.php。这不是权限问题,因为正在执行 index.php。任何人都可以帮助解决上述 Nginx 配置中的问题吗?任何帮助将不胜感激。
ls -la 从 pub 目录跟随
drwxr-xr-x 6 goodprice goodprice 4096 Nov 24 16:16 .
drwxr-xr-x 16 goodprice goodprice 4096 Nov 30 12:11 ..
-rw-rw-r-- 1 goodprice goodprice 1038 Nov 11 01:12 cron.php
-rwxrwxr-x 1 goodprice goodprice 102 Nov 10 23:04 deploy_clear_opcache.php
drwxrwxr-x 3 goodprice goodprice 4096 Nov 11 01:12 errors
-rw-rw-r-- 1 goodprice goodprice 2775 Nov 24 16:16 get.php
-rw-rw-r-- 1 goodprice goodprice 3329 Nov 11 01:12 health_check.php
-rw-rw-r-- 1 goodprice goodprice 6206 Nov 11 01:12 .htaccess
-rw-r--r-- 1 goodprice goodprice 1360 Nov 12 11:49 index.php
-rw-rw-r-- 1 goodprice goodprice 169 Jan 10 2021 info.php
drwxrwxr-x 67 goodprice goodprice 4096 Nov 29 00:01 media
drwxrwxr-x 3 goodprice goodprice 4096 Nov 11 01:12 opt
drwxr-xr-x 4 goodprice goodprice 4096 Nov 30 13:12 static
-rw-rw-r-- 1 goodprice goodprice 445 Nov 11 01:12 static.php
-rw-rw-r-- 1 goodprice goodprice 101 Nov 11 01:12 .user.ini
Php Fpm conf.d 文件提取用户和组。
group = "goodprice"
listen.group = "nobody"
listen.mode = 0660
listen.owner = "goodprice"
user = "goodprice"
nginx.conf如下
include /etc/nginx/conf.d/modules/*.conf;
user nobody;
worker_processes 1;
worker_rlimit_nofile 16384;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/conf.d-custom/*.conf;
}
【问题讨论】:
-
@Raptor 是的,但 index.php 的服务没有问题。我也会发布 php-fpm 配置。因为它正在监听 'nobody' 的 nginx 用户
-
这就是为什么我要求您检查是否有任何扩展属性在
ls -al中不可见 -
@raptor 是正确的,需要确保 nginx 和 php-fpm 用户都可以访问。 (应该没问题,但基于对每个人的阅读)。还要确保你正确地提供了 selinux 或 apparmor 等配置的东西。
-
@zochamx 我忘了提到我们在 CentOS 上。我会尝试将listen.owner 和listen.group 更改为“nobody”。看看这是否有效。问题是它曾经可以工作,但是自从迁移到 php 7.4 后它就停止了。
标签: php nginx magento2 nginx-config