当前位置: 首页 > 知识库问答 >
问题:

nginx php5 fpm失败(2:没有这样的文件或目录)

晏德佑
2023-03-14

问:我错过了什么或做错了什么?

我正在尝试将功能齐全的Zend Framework应用程序从带有mod_php5的Apache2迁移到带有php5 fpm的nginx。我会遇到这样的错误:

2012/06/27 12:08:04[error]1986#0:*1 open()“/var/www/public/sales/live trials json”失败(2:没有这样的文件或目录),客户端:*,服务器:www.mydomain。com,请求:“POST/sales/live trials json HTTP/1.1”,主机:“www.mydomain.com”,推荐人:https://www.mydomain.com/sales/live-trials“

下面是我的配置文件:

a) /etc/nginx/sites enabled/www

server {
  listen 80;
  listen 443 default ssl;

  server_name www.mydomain.com;
  root /var/www/public;

  ssl_certificate /etc/nginx/ssl/mydomain.crt;
  ssl_certificate_key /etc/nginx/ssl/mydomain.key;

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log error;

  index index.php index.phtml index.html;

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

  location ~* ^.+.(css|js|jpeg|jpg|gif|png|ico|xml) {
    access_log off;
    expires 30d;
  }

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

  location ~ /\.ht {
    deny all;
  }

  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_intercept_errors on;
    include /etc/nginx/fastcgi_params;
  }
}

b) /etc/nginx/fastcgi\u参数

fastcgi_param   QUERY_STRING        $query_string;
fastcgi_param   REQUEST_METHOD      $request_method;
fastcgi_param   CONTENT_TYPE        $content_type;
fastcgi_param   CONTENT_LENGTH      $content_length;
fastcgi_param   SCRIPT_FILENAME     $request_filename;
fastcgi_param   SCRIPT_NAME     $fastcgi_script_name;
fastcgi_param   REQUEST_URI     $request_uri;
fastcgi_param   DOCUMENT_URI        $document_uri;
fastcgi_param   DOCUMENT_ROOT       $document_root;
fastcgi_param   SERVER_PROTOCOL     $server_protocol;
fastcgi_param   GATEWAY_INTERFACE   CGI/1.1;
fastcgi_param   SERVER_SOFTWARE     nginx/$nginx_version;
fastcgi_param   REMOTE_ADDR     $remote_addr;
fastcgi_param   REMOTE_PORT     $remote_port;
fastcgi_param   SERVER_ADDR     $server_addr;
fastcgi_param   SERVER_PORT     $server_port;
fastcgi_param   SERVER_NAME     $server_name;
fastcgi_param   HTTPS           $https;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param   REDIRECT_STATUS     200;

c) /etc/php5/fpm/pool。d/www.conf

[www]
user = www-data
group = www-data
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 20
pm.start_servers = 4
pm.min_spare_servers = 2
pm.max_spare_servers = 6
chdir = /

d) ls-al/var/www

drwxr-xr-x  7 www-data www-data  4096 Jun 27 10:52 application
drwxr-xr-x  5 www-data www-data  4096 Jun 27 10:52 library
drwxr-xr-x 10 www-data www-data  4096 Jun 27 12:05 public

e)nginx-V

nginx version: nginx/1.1.19
TLS SNI support enabled
configure arguments:
  --prefix=/etc/nginx
  --conf-path=/etc/nginx/nginx.conf
  --error-log-path=/var/log/nginx/error.log
  --http-client-body-temp-path=/var/lib/nginx/body
  --http-fastcgi-temp-path=/var/lib/nginx/fastcgi
  --http-log-path=/var/log/nginx/access.log
  --http-proxy-temp-path=/var/lib/nginx/proxy
  --http-scgi-temp-path=/var/lib/nginx/scgi
  --http-uwsgi-temp-path=/var/lib/nginx/uwsgi
  --lock-path=/var/lock/nginx.lock
  --pid-path=/var/run/nginx.pid
  --with-debug
  --with-http_addition_module
  --with-http_dav_module
  --with-http_geoip_module
  --with-http_gzip_static_module
  --with-http_image_filter_module
  --with-http_realip_module
  --with-http_stub_status_module
  --with-http_ssl_module
  --with-http_sub_module
  --with-http_xslt_module
  --with-ipv6
  --with-sha1=/usr/include/openssl
  --with-md5=/usr/include/openssl
  --with-mail
  --with-mail_ssl_module
  --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-auth-pam
  --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-echo
  --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-upstream-fair
  --add-module=/build/buildd/nginx-1.1.19/debian/modules/nginx-dav-ext-module

f) php-v(这是cli版本,但我发誓我正在使用fpm运行nginx:)

PHP 5.3.10-1ubuntu3 with Suhosin-Patch (cli) (built: Apr 11 2012 17:25:33) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies

共有3个答案

晁聪
2023-03-14

如你所说你的问题是

location ~* ^.+.(css|js|jpeg|jpg|gif|png|ico|xml) {
  access_log off;
  expires 30d;
}

这与 /sales/live-trials-json的POST uri匹配,因为它没有锚定到uri路径的末尾,并且。匹配任何字符。这意味着'-js'匹配。要解决这个问题,您只需要添加一个\(以匹配文字'.')和一个$(以将匹配锚定在uri路径的末尾):

location ~* \.(css|js|jpeg|jpg|gif|png|ico|xml)$ {
  access_log off;
  expires 30d;
}
蒋培
2023-03-14

你的nginx配置是小错误。

因为同意您的规则,nginx尝试访问不存在的/var/www/public/sales/live-trials-json。

因为我不知道您的应用程序使用哪个endpoint,所以我建议您设置两个nginx位置。首先,为所有静态文件(使用regexp)创建此位置:

location ~* ^.+.(css|js|jpeg|jpg|gif|png|ico|xml) {
    access_log off;
    expires 30d;
  }

所有其他查询都应该代理到apache:

  location / {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_intercept_errors on;
    include /etc/nginx/fastcgi_params;
  }

对这条规则稍作修改:

  location ~* ^/(favicon.ico|robots.txt)$ {
    access_log off;
    log_not_found off;
  }

当然,您可以保留“. ht设置”不变:

  location ~ /\.ht {
    deny all;
  }

因此,最终配置为:

server {
  listen 80;
  listen 443 default ssl;

  server_name www.mydomain.com;
  root /var/www/public;

  ssl_certificate /etc/nginx/ssl/mydomain.crt;
  ssl_certificate_key /etc/nginx/ssl/mydomain.key;

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log error;

  index index.php index.phtml index.html;

  location ~* ^/(favicon.ico|robots.txt)$ {
    access_log off;
    log_not_found off;
  }

  location ~* ^.+.(css|js|jpeg|jpg|gif|png|ico|xml) {
    access_log off;
    expires 30d;
  }

  location ~ /\.ht {
    deny all;
  }

  location / {
    fastcgi_pass 127.0.0.1:9000;
# I'm not sure that this setting is needed:
#        fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_intercept_errors on;
    include /etc/nginx/fastcgi_params;
  }


}
卢才艺
2023-03-14

好吧,经过漫长而疲惫的挣扎,我终于找到了这种疯狂。所以,我从零开始了一切,以下是我学到的:

整个奇怪之处就在location~*的某个地方。。。{ ... } ,所以无论谁有更好的经验,请解释原因:-)同时我将管理应用层上的资产和缓存。

我的功能配置文件如下所示:

server {
  listen 80;
  listen 443 default ssl;

  server_name www.mydomain.com;
  root /var/www/public;

  ssl_certificate /etc/nginx/ssl/mydomain.crt;
  ssl_certificate_key /etc/nginx/ssl/mydomain.key;

  access_log /var/log/nginx/access.log;
  error_log /var/log/nginx/error.log error;

  index index.php index.phtml index.html;

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

  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_intercept_errors on;
    include /etc/nginx/fastcgi_params;
  }
}

谢谢你的尝试,尤其是@sarnold和@sergei-lomakov!

 类似资料:
  • 问题内容: 我正在尝试安装berta(v 0.6.3b),但出现此错误: 警告:session_start()[function.session-start]:打开(/ var / php_sessions / sess_a0d6b8422181739d10066fb60cebfe5d,O_RDWR)失败:/hermes/bosweb/web010/b100/ipg.ellieniemeyerco

  • 我不知道这里出了什么问题...我试着把这个写得更简洁些,但没有奏效。我在阅读了这个问题的其他建议后加入了所有额外的字符串。帮不上忙。不知道发生了什么。可能是权限相关的吗?AFAIK我正试图写入内存,这不需要特殊的权限? 它每次都是“制造dirs”,目录不是停留在制造,或者其他什么。当它到达myfile.createnewfile()时;它给出错误消息“Open Failed:ENOENT(没有这样

  • 如标题中所述,我试图在我局域网中的远程服务器上托管的Docker机器中使用Py魅力专业版(2018.2)和python远程解释器。我通过遵循帮助https://www.jetbrains.com/help/pycharm/using-docker-as-a-remote-interpreter.html创建了一个非常简单的示例。 Pycharm 2018.2安装在debian发行版的LAN pc(

  • 我有一个错误: 警告:require_once(../questionTypes/Question.php):无法打开流:第25行的/home/u949913003/public_html/includes/essential.php中没有此类文件或目录 致命错误:require_once():无法在/home/u949913003/public_html/includes/essential.p

  • null 我在用这个代码 但我一直得到这个错误