1、首先安装nginx,这里采用编译安装

useradd -M -s /sbin/nologin nginx
安装一些依赖包:
yum -y install pcre-devel libxslt-devel gd gd-devel

GeoIP GeoIP-devel 最后的这两个包,需要epel源进行安装
 
note:epel源安装
cd /etc/yum.repos.d
rpm -ivh epel-release-latest-6.noarch.rpm
 
2、nginx的安装
cd /root/tools
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar xf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-file-aio --with-ipv6 --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_stub_status_module
make && make install
 
3、php的安装,这里不做介绍,看博客以前的文章即可
 
4、结合fastcgi协议
启用nginx配置文件支持fastcgi:
location / {
root html;
index index.html index.htm index.php; 第一步修改
}

location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME html$fastcgi_script_name;第二步修改

include fastcgi_params;
}

fastcgi_param指令指定放置PHP动态程序的主目录,也就是$fastcgi_script_name前面指定的路径,这里是/usr/local/nginx/html目录,建议将这个目录与Nginx虚拟主机指定的根目录保持一致,当然也可以不一致
由于nginx编译安装,nginx的网站根目录在/usr/local/nginx/html,相对路径为html
所以这里设置html
 
然后在fastcgi_params配置文件中加入以下一行:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;第三步修改
修改后的fastcgi_params文件如下:

[root@wadeson nginx]# cat conf/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_NAME $fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$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;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

执行完上面三步之后,编写php文件确认是否成功:

[root@wadeson nginx]# cat html/index.php
<?php
phpinfo();
?>

访问浏览器查看效果:

note:如果需要在现有的基础上编译一个新的模块,那么重新执行configure,后面加上参数

编译参数之后加上--add-module=PATH
重新再次编译一次

nginx结合fastcgi的更多相关文章

  1. Nginx中FastCGI配置优化

    FastCGI: FastCGI是从CGI发展改进而来的.传统CGI接口方式的主要缺点是性能很差,因为每次HTTP服务器遇到动态程序时都需要重新启动脚本解析器来执行解析,然后结果被返回给HTTP服务器 ...

  2. nginx、fastCGI、php-fpm关系梳理(转)

    前言: Linux下搭建nginx+php+memached(LPMN)的时候,nginx.conf中配需要配置fastCGI,php需要安装php-fpm扩展并启动php-fpm守护进程,nginx ...

  3. Nginx + CGI/FastCGI + C/Cpp

    接着上篇<Nginx安装与使用>,本篇介绍CGI/FASTCGI的原理.及如何使用C/C++编写简单的CGI/FastCGI,最后将CGI/FASTCGI部署到nginx.内容大纲如下: ...

  4. nginx、fastCGI、php-fpm关系梳理(转载 http://blog.sina.com.cn/s/blog_6df9fbe30102v57y.html)

        前言: Linux下搭建nginx+php+memached(LPMN)的时候,nginx.conf中配需要配置fastCGI,php需要安装 php-fpm扩展并启动php-fpm守护进程, ...

  5. 利用Nginx+Mono+Fastcgi代替IIS对Asp.Net进行反向代理

    Nginx的好处相信我不必多说了,它作为一个相当轻量级的开源Web 服务器以及反向代理服务器而深受欢迎.越来越多的公司已经对它产生兴趣,包括我们公司的许多部门,利用它进行负载均衡和资源管理,之前写过一 ...

  6. etrace跟踪Nginx代码+ FASTCGI

    http://blog.csdn.net/jianqiangchen/article/details/29175285 http://blog.csdn.net/jianqiangchen/artic ...

  7. nginx、fastCGI、php-fpm关系梳理(转载参考)

    nginx.fastCGI.php-fpm关系梳理 还可以参考:http://www.cnblogs.com/skynet/p/4173450.html   前言: Linux下搭建nginx+php ...

  8. Linux上配置Nginx+PHP5(FastCGI)

    原为地址:http://www.laruence.com/2009/07/28/1030.html Nginx是俄罗斯人编写的十分轻量级的HTTP服务器,以事件驱动的方式编写,所以有非常好的性能,同时 ...

  9. nginx、fastCGI、php-fpm关系梳理

    前言: Linux下搭建nginx+php+memached(LPMN)的时候,nginx.conf中配需要配置fastCGI,php需要安装php-fpm扩展并启动php-fpm守护进程,nginx ...

  10. Nginx 中 FastCGI 配置示例

    nginx 中 FastCGI 参数:主要是在 http 层 :保证PHP环境的高校运行 主要对PHP用来解析 fastcgi_cache_path /tmp/fastcgi_cache levels ...

随机推荐

  1. Oracle的存储过程编程

    是一个可以用编程的方式来操作SQL的集合. | |目录 1什么是存储过程? 2存储过程的优点? 3存储过程的缺点? 4存储过程的用途? 5存储过程注意事项? 6如何写存储过程? 7如何执行存储过程? ...

  2. [LeetCode] 1.Two Sum - Swift

    1. Two Sum Given an array of integers, return indices of the two numbers such that they add up to a ...

  3. C. Mail Stamps---cf29c(离散化,图)

    题目链接:http://codeforces.com/problemset/problem/29/C 题意就是有n(1e5)个点,找到一条能把所有的点都包含在内的路径,由于点的编号是 1e9 所以不得 ...

  4. mysql 复合查询语句

    INSERT INTO runwa(rshottime,rmoney,renamecount) VALUES (CURDATE(),(select SUM(MONEY) from income whe ...

  5. python 简单的文件下载

    需要使用urllib2库 import urllib2def download(url, szFileName = ""): #szFileName:下载文件到的目标路径 if s ...

  6. 《Monitoring and Tuning the Linux Networking Stack: Receiving Data》翻译

    Overview 从宏观的角度来看,一个packet从网卡到socket接收缓冲区的路径如下所示: 驱动加载并初始化 packet到达网卡 packet通过DMA被拷贝到内核中的一个ring buff ...

  7. Python面向对象高级

    一  反射 反射也可以说是python的自省机制 反射就是通过字符串的形式,导入模块,然后以字符串的形式去查找指定函数并执行.利用字符串的形式去模块(对象)中操作(查找/获取/添加/删除)属性,是一种 ...

  8. 消息编解码Nanopb - protocol buffers

    Google Protocol Buffer 有各种版本的代码包,Python C/C++.JAVA.C.OBJ-C..NET等,嵌入式设备中使用的protobuf版本,我们选择的是nanoprobu ...

  9. python学习笔记(七)操作mysql

    python操作mysql数据库需要先安装pymysql模块,在之前博客中可翻看如何安装,最简单的就是pip install pymysql 1.导入pymysql模块   import pymysq ...

  10. Spark应用日志级别设置

    一. 日志效率原因 开发时,控制台输出一大堆日志信息,严重影响查看日志效率.   从控制台输出日志我们可以看出,应用程序是默认加载Spark-core包下面的log4j-defaults.proper ...