Dec 23

[原]在红旗Asianux 3.0上使用Nginx+PHP+Mysql 阴

linuxing , 18:23 , 网络服务 » 常见服务 , 评论(0) , 引用(0) , 阅读(18152) , Via 本站原创 | |
    Nginx (”engine x”) 是一个高性能的 HTTP 和反向代理服务器,也是一个 IMAP/POP3/SMTP 代理服务器。由于其高效和稳定,国内很多网站都转用了其作为代理或HTTP服务端。网上介绍在Centos 5.x上的部署文档很多,今天也是从这里看到介绍,红旗上的步骤基本相同。

一、安装
Nginx 官方网站:http://www.nginx.net/
目前稳定版本是0.6.34,可顺利在红旗 Asianux 3.0 sp1上编译。这里还提供rpm包下载,于是我拿源码重编了一个。
nginx-0.6.34-1qk版本(使用Asianux 3.0上自带的pcre、、zlib、openssl库文件)

源码:

安装执行:

# rpm -ivh nginx-0.6.34-1qk.i386.rpm

访问:
引用
# service nginx start
启动 nginx:                                               [确定]
# netstat -ln|grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN

界面:
点击在新窗口中浏览此图片

二、配置
1、安装FastCGI模块
Nginx可通过FastCGI模式运行PHP,但其没有自带FastCGI daemon,通常就是用lighttpd-fastcgi实现的:

# yum install lighttpd-fastcgi

lighttpd-fastcgi的包,请从另一篇日志下载,点击
2、修改php.ini配置
修改/etc/php.ini文件,再最后增加:
引用
cgi.fix_pathinfo = 1

4、确认已经安装php-cgi
引用
# type php-cgi
php-cgi is /usr/bin/php-cgi

5、创建一个执行用户

# useradd -M nginx

5、使用spawn-fcgi执行PHP

# /usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid
spawn-fcgi.c.207: child spawned successfully: PID: 8405

6、修改nginx配置
编辑/etc/nginx/nginx.conf,参考原有注释,在注释下面增加:
引用
location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
            include        fastcgi_params;
        }

并修改两个值:
引用
worker_processes  5;
keepalive_timeout  2;

7、创建测试页面,并访问
测试页面:

# mkdir -p /usr/share/nginx/html
# echo "<? phpinfo(); ?>" > /usr/share/nginx/html/info.php

重启服务:
引用
# service nginx restart
停止 nginx:                                               [确定]
启动 nginx:                                               [确定]

访问界面:
点击在新窗口中浏览此图片
Mysql支持:
点击在新窗口中浏览此图片
服务端信息:
点击在新窗口中浏览此图片

8、开机自动运行
若一切正常,应设为自启动方式:

# chkconfig --level 35 nginx on
# echo "/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid" >> /etc/rc.local


三、参考资料
Installing Nginx With PHP5 And MySQL Support On Fedora 10
Nginx 常见应用技术指南(Nginx Tips)[定期更新]
Tags: ,
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]