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. Docker的基本使用(部署python项目)

    今天开始利用docker来部署项目,当然,首先,需要安装好Docker,这个在我的上篇中写了 一.准备项目 我写的是一个爬取某ppt网站的代码,就一个ppt1.py是爬虫,然后,ppts是存放下载的p ...

  2. 160519、Oracle中将查询出的多条记录的某个字段拼接成一个字符串的方法

    with temp as( select 'China' nation ,'Guangzhou' city from dual union all select 'China' nation ,'Sh ...

  3. POJ 3233 Matrix Power Series(矩阵快速幂)

    Matrix Power Series Time Limit: 3000MS Memory Limit: 131072K Total Submissions: 19338 Accepted: 8161 ...

  4. Net Core MVC6 RC2 启动过程分析

    入口程序 如果做过Web之外开发的人,应该记得这个是标准的Console或者Winform的入口.为什么会这样呢?.NET Web Development and Tools Blog ASP.NET ...

  5. Buy a home in AU

    澳洲留学生买房的几点注意事项: 1. 新房.楼花.或者买地建房,完全不受限制,国民待遇,是政府鼓励的. 2. 留学生签证剩余超12个月,可以购买二手房,但是只能自住不能出租. 3. 银行可以提供50% ...

  6. csv的文件excel打开长数字后面位变0的解决方法

    对于有大数字的CSV文件,应使用导入,而不是打开.这里以Excel2010为例,其它版本也可以参照: 打开Excel,此时Excel内为空白文档 点击工具栏中的[数据]→[自文本] 在“导入文本文件” ...

  7. MapReduce自定义InputFormat和OutputFormat

    一.自定义InputFormat 需求:将多个小文件合并为SequenceFile(存储了多个小文件) 存储格式:文件路径+文件的内容 c:/a.txt I love Beijing c:/b.txt ...

  8. Python的一些教程(转)

    原文:http://blog.chinaunix.net/uid-26200547-id-3418038.html Python 安装配置及基本语法篇 Python 语言速成 Python 基本知识  ...

  9. qemu网络虚拟化之数据流向分析三

    2016-09-27 前篇文章通过分析源代码,大致描述了各个数据结构之间的关系是如何建立的,那么今天就从数据包的角度,分析下数据包是如何在这些数据结构中间流转的! 这部分内容需要结合前面两篇文章来看, ...

  10. GCJ 2015R2(Bilingual-最小割)

    Problem C. Bilingual Problem Elliot's parents speak French and English to him at home. He has heard ...