php - 如何在 PHP 中使用 nginx?

标签 php nginx

将 PHP 与 nginx 一起使用的好方法是什么?从我得到的发现来看,也许使用 PHP-FPM 可能是将 PHP 交给 nginx 的好方法。

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

谢谢。

最佳答案

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

编辑(可能需要在您的网站 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 - 如何在 PHP 中使用 nginx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3398281/

相关文章:

php - 电子邮件服务器;如何配置 postfix 以满足我的需要? (我需要 SASL 或/和 TLS 吗?)

NGINX 有条件地打开/关闭 proxy_intercept_errors

ssl - Nginx 上游到 https 主机 - ssl3_get_record :wrong version number

ssl - 安装了 SSL 证书,但仍然暴露于中间人攻击

javascript - 将 DIV 分配给 php 变量并在多个隐藏输入上循环

php - 如何修复更新 MySQL 表中的信息时出现的错误?

php - Symfony 与 nginx 不提供 .js 和 .css 文件

python - flask如何处理web api

php - PHP的每个错误级别中包含什么

javascript - 如何使用 Angular $http 将数据 POST 到 PHP