如何正确配置Nginx+PHP
1个回答
2015-11-08
展开全部
1、Nginx安装
安装编译软件库
[root@leixuesong ~]# yum -y install gcc gcc-c++ autoconf automake openssl openssl-devel pcre-devel zlib-devel
下载nginx 1.6.2源码包
[root@leixuesong ~]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
解压nginx
[root@leixuesong ~]# tar zxvf nginx-1.6.2.tar.gz
进入解压文件夹
[root@leixuesong ~]# cd nginx-1.6.2
编译设置模块
[root@leixuesong nginx-1.6.2]# ./configure –with-http_stub_status_mocule –prefix=/opt/nginx
安装
[root@leixuesong nginx-1.6.2]# make && make install
nginx编译安装性能优化
1、在nginx 源码文件找到auto/cc/gcc文件找到如下几行
#debug
[root@leixuesong ~]# CFLASS=”$CFLAGS -g”
2、特定CPU优化CPU类型编译
–with-cc-opt=”-O3″
–with-cpu-opt=CPU类型
查看CPU类型
[root@leixuesong ~]# cat /proc/cpuinfo | grep “model name”
nginx重新启动
[root@leixuesong ~]# /opt/nginx/sbin/nginx -s reload
nginx启动
[root@leixuesong ~]# /opt/nginx/sbin/nginx
nginx检测配置
[root@leixuesong ~]# /opt/nginx/sbin/nginx -t
2、PHP的安装和配置
安装php依赖软件库
[root@leixuesong ~]# yum install -y gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel mysql mysql-devel
下载php5.6源码包
[root@leixuesong ~]# wget http://am1.php.net/distributions/php-5.6.3.tar.gz
解压
[root@leixuesong ~]# tar -zxvf php-5.6.3.tar.gz
[root@leixuesong ~]# cd php-5.6.3
编译设置模块
[root@leixuesong php-5.6.3]# ./configure –prefix=/usr/local/php –with-mysql=mysqlnd–with-mysqli=mysqlnd –enable-fpm –with-pear –with-curl –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv –with-mhash –with-zlib –enable-mbstring –disable-debug
make && make install
复制php配置文件
[root@leixuesong php-5.6.3]# cp php.ini-production /opt/php/lib/php.ini
启动php-fpm
[root@leixuesong php-5.6.3]# /opt/php/sbin/php-fpm
检测配置是否正确
[root@leixuesong php-5.6.3]# /opt/php/sbin/php-fpm -t
在centos上成功编译安装nginx 1.6、php 5.6并成功启动nginx和php-fpm后,访问php提示”File not found.”,同时在错误日志中看到:
2013/10/22 20:05:49 [error] 12691#0: *6 FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream, client: 192.168.168.1, server: localhost, request: “GET / HTTP/1.1″, upstream: “fastcgi://127.0.0.1:9000″, host: “192.168.168.133”:
在Nginx配置文件中找到定义调用脚本文件的地方,如:
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
修改成如下方式($document_root):
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
nginx gzip设置
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css applocation/xml;
gzip_vary on;
来源:CentOS编译安装Nginx1.6、PHP5.6 - http://www.leixuesong.cn/84
安装编译软件库
[root@leixuesong ~]# yum -y install gcc gcc-c++ autoconf automake openssl openssl-devel pcre-devel zlib-devel
下载nginx 1.6.2源码包
[root@leixuesong ~]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
解压nginx
[root@leixuesong ~]# tar zxvf nginx-1.6.2.tar.gz
进入解压文件夹
[root@leixuesong ~]# cd nginx-1.6.2
编译设置模块
[root@leixuesong nginx-1.6.2]# ./configure –with-http_stub_status_mocule –prefix=/opt/nginx
安装
[root@leixuesong nginx-1.6.2]# make && make install
nginx编译安装性能优化
1、在nginx 源码文件找到auto/cc/gcc文件找到如下几行
#debug
[root@leixuesong ~]# CFLASS=”$CFLAGS -g”
2、特定CPU优化CPU类型编译
–with-cc-opt=”-O3″
–with-cpu-opt=CPU类型
查看CPU类型
[root@leixuesong ~]# cat /proc/cpuinfo | grep “model name”
nginx重新启动
[root@leixuesong ~]# /opt/nginx/sbin/nginx -s reload
nginx启动
[root@leixuesong ~]# /opt/nginx/sbin/nginx
nginx检测配置
[root@leixuesong ~]# /opt/nginx/sbin/nginx -t
2、PHP的安装和配置
安装php依赖软件库
[root@leixuesong ~]# yum install -y gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel mysql mysql-devel
下载php5.6源码包
[root@leixuesong ~]# wget http://am1.php.net/distributions/php-5.6.3.tar.gz
解压
[root@leixuesong ~]# tar -zxvf php-5.6.3.tar.gz
[root@leixuesong ~]# cd php-5.6.3
编译设置模块
[root@leixuesong php-5.6.3]# ./configure –prefix=/usr/local/php –with-mysql=mysqlnd–with-mysqli=mysqlnd –enable-fpm –with-pear –with-curl –with-gd –with-jpeg-dir –with-png-dir –with-freetype-dir –with-iconv –with-mhash –with-zlib –enable-mbstring –disable-debug
make && make install
复制php配置文件
[root@leixuesong php-5.6.3]# cp php.ini-production /opt/php/lib/php.ini
启动php-fpm
[root@leixuesong php-5.6.3]# /opt/php/sbin/php-fpm
检测配置是否正确
[root@leixuesong php-5.6.3]# /opt/php/sbin/php-fpm -t
在centos上成功编译安装nginx 1.6、php 5.6并成功启动nginx和php-fpm后,访问php提示”File not found.”,同时在错误日志中看到:
2013/10/22 20:05:49 [error] 12691#0: *6 FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream, client: 192.168.168.1, server: localhost, request: “GET / HTTP/1.1″, upstream: “fastcgi://127.0.0.1:9000″, host: “192.168.168.133”:
在Nginx配置文件中找到定义调用脚本文件的地方,如:
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
修改成如下方式($document_root):
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
nginx gzip设置
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css applocation/xml;
gzip_vary on;
来源:CentOS编译安装Nginx1.6、PHP5.6 - http://www.leixuesong.cn/84
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询