简体   繁体   English

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

[英]nginx php5-fpm failed (2: No such file or directory)

QUESTION: What am I missing or doing wrong? 问题:我错过了什么或做错了什么?

I'm trying to migrate fully functional Zend Framework application from Apache2 with mod_php5 to nginx with php5-fpm. 我正在尝试使用php5-fpm将完全功能的Zend Framework应用程序从带有mod_php5的Apache2迁移到nginx。 I get this kind of errors: 我遇到这种错误:

2012/06/27 12:08:04 [error] 1986#0: *1 open() "/var/www/public/sales/live-trials-json" failed (2: No such file or directory), client: *.*.*.*, server: www.mydomain.com, request: "POST /sales/live-trials-json HTTP/1.1", host: "www.mydomain.com", referrer: "https://www.mydomain.com/sales/live-trials"

Here are my configuration files: 这是我的配置文件:

a) /etc/nginx/sites-enabled/www 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_params b)/ etc / nginx / fastcgi_params

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 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 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 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 (this is cli version, but I swear I am running nginx with fpm:) 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

Alright, after long and exhausting struggles, I've managed to figure out this madness. 好吧,经过漫长而艰辛的挣扎,我已经设法弄清楚这种疯狂。 So, I've started everything from scratch and here is what I've learned: 所以,我从零开始做了所有事情,这是我所学到的:

Entire weirdness is somewhere in location ~* ... { ... } , so whoever have better experience, please explain why :-) Meanwhile I'll manage assets and caching on application layer. 整个奇怪的地方位于某个地方location ~* ... { ... } ,所以无论谁有更好的经验,请解释原因:-)同时我将管理资产和应用层缓存。

My functional configuration file looks like this: 我的功能配置文件如下所示:

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;
  }
}

Thanks for trying, especially @sarnold and @sergei-lomakov! 感谢您的努力,特别是@sarnold和@ sergei-lomakov!

Your nginx configuration is little wrong. 你的nginx配置有点不对劲。

Because agree with your rules, nginx tries to access /var/www/public/sales/live-trials-json which doesn't exist. 因为同意你的规则,nginx试图访问不存在的/ var / www / public / sales / live-trials-json。

Because I don't know which endpoints your application use, I suggest you to make two nginx locations. 因为我不知道您的应用程序使用哪个端点,我建议您创建两个nginx位置。 First , for all static files (with regexp) create this location: 首先,对于所有静态文件(使用regexp)创建此位置:

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

All another queries should be proxied to apache: 所有其他查询应该代理到apache:

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

Make little change with this rule: 使用此规则稍作修改:

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

Of course, you can leave ".ht settings" untouched: 当然,您可以保持“.ht设置”不变:

  location ~ /\.ht {
    deny all;
  }

So, Final config will be: 所以,最终配置将是:

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;
  }


}

As you noted, your problem is with 如你所说,你的问题是

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

This matches your POST uri of /sales/live-trials-json because it hasn't been anchored to the end of the uri path, and . 这匹配你的/ uri / sales / live-trials-json的POST uri,因为它还没有被锚定到uri路径的末尾,并且。 matches any character. 匹配任何角色。 This means that '-js' matches. 这意味着'-js'匹配。 To fix this, you just need to add a \\ (to match a literal '.') and a $ (to anchor the match at the end of the uri path): 要解决此问题,您只需要添加\\(以匹配文字'。')和$(以在uri路径的末尾锚定匹配):

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Nginx + Php-fpm + Zend Framework 1.11奇怪的重写错误 - Nginx + Php-fpm + Zend Framework 1.11 strange rewrite error php-fpm每个池一个错误日志文件 - php-fpm one error log file per pool “无法打开流:没有这样的文件或目录”,但是文件在PHP的include_path中 - “failed to open stream: No such file or directory”, but the file is in PHP's include_path 无法打开流:没有这样的文件或目录 - Failed to open stream: No such file or directory ZendFramework 1.12和PHPUnit错误:include_once(PageRegex.php):无法打开流:没有这样的文件或目录 - ZendFramework 1.12 and PHPUnit Error: include_once(PageRegex.php): failed to open stream: No such file or directory 得到“ require_once(Zend / Loader / Autoloader.php):打开流失败:没有这样的文件或目录” - Getting “require_once(Zend/Loader/Autoloader.php): failed to open stream: No such file or directory” 警告:require_once(Zend / Application.php):无法打开流:/ var / w中没有这样的文件或目录 - Warning: require_once(Zend/Application.php): failed to open stream: No such file or directory in /var/w 无法打开流:不需要此类文件或目录,也无法打开 - Failed to open stream: No such file or directory & Failed opening required 警告:require_once(Zend / Application.php)[function.require-once]:无法打开流:没有这样的文件或目录 - Warning: require_once(Zend/Application.php) [function.require-once]: failed to open stream: No such file or directory 无法打开流:/ usr / bin / phpunit中没有这样的文件或目录 - failed to open stream: No such file or directory in /usr/bin/phpunit
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM