nginx结合fastcgi

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();
?>

访问浏览器查看效果:

nginx结合fastcgi

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

编译参数之后加上--add-module=PATH
重新再次编译一次
上一篇:LINUX_RHEl6_DHCP服务器配置


下一篇:idea jvm 优化