如何在 PHP 中使用 nginx? [英] How to use nginx with PHP?

查看:31
本文介绍了如何在 PHP 中使用 nginx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 nginx 中使用 PHP 的好方法是什么?从我得到的发现来看,也许使用 PHP-FPM 可能是在 nginx 后面处理 PHP 的好方法.

What is a good way of using PHP with nginx? From the finding I got, maybe using PHP-FPM might be a good way of handing PHP behind nginx.

我们遇到的问题是我们提供的基于 Web 的免费 API 收到大量请求(每天大约 500K),请求大多非常短且规模小,但 Apache 消耗大量内存.想试试nginx看看能不能处理的更好.

The problem we have is that the free web based API we serve gets a lot of request (about 500K a day), the requests are mostly very short and small in size but Apache is consuming a lot of memory. I want to try nginx to see if it can handle it better.

谢谢.

推荐答案

  1. Ubuntu Lucid 64 位
  2. apt-get 安装 nginx
  3. apt-get 更新
  4. apt-get install php5-cli php5-common php5-suhosin
  5. apt-get install python-software-properties
  6. add-apt-repository ppa:brianmercer/php
  7. apt-get 更新 &&apt-get install php5-fpm php5-cgi
  8. /etc/init.d/nginx restart
  9. /etc/init.d/php5-fpm restart

编辑(可能需要在您的站点配置中使用):

Edit (might need this in your site conf) :

    location ~ .php$ {
        fastcgi_read_timeout 60000;
        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        fastcgi_param   SCRIPT_FILENAME /var/www/site$fastcgi_script_name;
        include         fastcgi_params;
    }
    location ~ /.ht {
            deny  all;
    }

这篇关于如何在 PHP 中使用 nginx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆