加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

macos – Nginx PHP-FPM在Mountain Lion上非常慢

发布时间:2020-12-13 21:29:49 所属栏目:Nginx 来源:网络整理
导读:我在运行ML的MacBook上用PHP-FPM设置了Nginx.它工作正常但我在浏览器中运行页面时需要5到10秒才能连接.甚至以下PHP脚本: 大约需要5秒钟才能连接.我正在使用Chrome,我在状态栏中收到“发送请求”消息大约7秒钟.如果我再次刷新它似乎立即工作,但如果我离开它

我在运行ML的MacBook上用PHP-FPM设置了Nginx.它工作正常但我在浏览器中运行页面时需要5到10秒才能连接.甚至以下PHP脚本:

大约需要5秒钟才能连接.我正在使用Chrome,我在状态栏中收到“发送请求”消息大约7秒钟.如果我再次刷新它似乎立即工作,但如果我离开它大约10秒钟它将再次“睡觉”.就好像nginx或PHP会睡觉然后再花几年时间再醒来.

编辑:这也影响服务器上的静态文件,因此它似乎是DNS或nginx的问题.

任何人都可以帮我找出造成这种情况的原因吗?

nginx.conf

worker_processes 2;

events {
   worker_connections 1024;
}

http {
    include mime.types;
   default_type text/plain;
   server_tokens off;
   sendfile on;
   tcp_nopush on;
   keepalive_timeout 1;
   gzip on;
   gzip_comp_level 2;
   gzip_proxied any;
   gzip_types text/plain text/css text/javascript application/json application/x-javascript text/xml application/xml application/xml+rss;

   index index.html index.php;

   upstream www-upstream-pool{
      server unix:/tmp/php-fpm.sock;
   }

  include sites-enabled/*;
}

PHP-fpm.conf

[global]
pid = /usr/local/etc/php/var/run/php-fpm.pid
; run in background or in foreground?
; set daemonize = no for debugging
                         daemonize = yes

include=/usr/local/etc/php/5.4/pool.d/*.conf

pool.conf

[www]
user=matt
group=staff
pm = dynamic
pm.max_children = 10
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 10
pm.max_requests = 500
listen = /tmp/php-fpm.sock
;listen = 127.0.0.1:9000
php_flag[display_errors] = off

网站可用/ CFT

server {
   listen 80;
   server_name cft.local;
   root /Users/matt/Sites/cft/www;
   access_log /Users/matt/Sites/cft/log/access.log;
   error_log /Users/matt/Sites/cft/log/error.log;
   index index.php;

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

   include fastcgi_php_default.conf;
}

fastcgi_php_default.conf

fastcgi_intercept_errors on;

location ~ .php$
    {
    fastcgi_split_path_info ^(.+.php)(/.+)$;

    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    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_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  HTTPS              $https if_not_empty;

    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 PATH_INFO         $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED   $document_root$fastcgi_path_info;

    fastcgi_read_timeout 300;

    fastcgi_pass www-upstream-pool;

    fastcgi_index index.php;
}

fastcgi_param  REDIRECT_STATUS    200;
最佳答案
一个原因可能是 – 正如上面已经怀疑的那样 – 您的服务器运行正常,但DNS查找有问题.

如此长的时间通常是由尝试超时引起的,然后重试其他方式,工作,缓存.

缓存工作请求可以解释为什么第二个http请求很快.

我几乎可以肯定,这是由DNS查找引起的,它试图查询无法访问的服务,在超时时间后放弃,然后尝试工作服务并将结果缓存几分钟.

Apple has recently made a significant change in how the OS handles requests for “.local” name resolution that can adversely affect Active Directory authentication and DFS resolution.

When processing a “.local” request,the Mac OS now sends a Multicast DNS (mDNS) or broadcast,then waits for that request to timeout before correctly sending the information to the DNS server. The delay caused by this results in an authentication failure in most cases.

http://www.thursby.com/local-domain-login-10.7.html

他们提供将超时设置为最小可能值,显然仍然是1秒 – 不是真的令人满意.

我建议使用localhost或127.0.0.1或尝试http://test.dev作为本地域

/ etc / hosts文件

127.0.0.1 localhost test.dev

编辑
在OSX中,.local似乎是LAN设备的保留tld.使用上面建议的其他域名将def.解决这个问题

http://support.apple.com/kb/HT3473

编辑2
找到这篇精彩的文章,它准确地描述了您的问题以及如何解决它

http://www.dmitry-dulepov.com/2012/07/os-x-lion-and-local-dns-issues.html?m=1

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读