飞嗨,欢迎您的光临,本博所发布之文章皆为作者亲测通过,如有错误,欢迎通过各种方式指正。(本博已于2015.12.6升级到php7,运行环境php7 php-fpm + nginx1.8.0)

nginx使用php-fpm

Linux lf 2883℃ 0评论

之前,前置机用的nginx,后端机器用的是apache,apache使用的mod_php方式处理php脚本的。php在新版本中,已经默认会装上php-fpm这个fastcgi管理方式,趁着项目没上线,就把后端apache机器改成php-fpm+nginx的方式,结果并发性能提高了3倍(偶们java童鞋用多线程自己写的测试工具)

php-fpm

 php-fpm

安装nginx1.8.0最新稳定版:

1. cd /usr/src
2. wget http://nginx.org/download/nginx-1.8.0.tar.gz   1.8.0为最新stable版本
3. tar -xvf nginx-1.8.0.tar.gz
4. cd nginx-1.8.0  5. /usr/local/nginx
6../configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --with-http_stub_status_module

安装php的php-fpm只需要在执行configure脚本的时候加入–enable-fpm,最后把php-fpm.conf.default配置拷贝到php的etc配置目录下,并取消daemoize=yes的注释

php-fpm的启动/停止/重启脚本,php官方已经写好了,只需要拷贝php源码安装目录/sapi/fpm/init.d.php-fpm到/etc/init.d下面,不要忘记给予x权限。

配置nginx以php-fpm处理php脚本:

server{
          listen 80;
          server_name www.xxx.com;
          access_log logs/xxx.access.log;
          location /{
               index index.html index.php;
               root /var/www/xxx/;
               #try_files $uri $uri/ /index.php?$args;
          }
          location ~ \.php$ {
             root           /var/www/xxx/;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        fastcgi_params;
         }

     }
一般配置出问题的都是fastcgi_param这里,当nginx把脚本文件名传给php-fpm的时候,要注意路径,否则很容易造成php在错误的目录中找脚本文件。好吧,我就在这里被坑了很久

转载请注明:飞嗨 » nginx使用php-fpm

喜欢 (6)or分享 (0)
发表我的评论
取消评论
表情
(7)个小伙伴在吐槽
  1. isotretinoin order internet no physician approval http://cialibuy.com - Buy Cialis On Sale Online Worldwide Stendra 100mg Legally Cialis Online Doxycycline Forum
    匿名2020-01-24 05:13 (17小时前)回复
  2. Best Price Viagra 100mg http://cialibuy.com - Cialis Reviews Of Propecia Use Cialis Alquiler Kamagra
    匿名2020-01-24 03:22 (19小时前)回复
  3. Pharmacy Cheapest http://cialibuy.com - buy cialis online Propecia Abgelaufen cheapest cialis 20mg Amoxicillin Max Dose
    匿名2020-01-23 06:06 (2天前)回复
  4. Pump It Global Caplet Was Ist Cialis 20mg Reactions To Cephalexin generic cialis Buying Viagra Overseas Order Discount Secure Ordering Bentyl Merbentyl Medicine Cheapeast Online Propecia Working Hair Loss Treatment
    匿名2020-01-20 10:07 (4天前)回复
  5. Commander Nolvadex Buy Cialis Cialis 10mg Doctissimo Levitra Cuanto Tomar Priligy Generico Farmacia
    匿名2020-01-20 03:41 (5天前)回复
  6. Tadalafil Without Perscription Cialis Cialis Retardante Online No Script Pharmacy
    匿名2020-01-17 16:20 回复
  7. Cipro And Amoxicillin Toghter Cialis Cialis 5mg Wirkstoff
    匿名2020-01-17 01:50 回复
粤ICP备15018643号-1