免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5024 | 回复: 1
打印 上一主题 下一主题

yum 安装nginx(教程7) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-05-25 09:12 |只看该作者 |倒序浏览
Nginx 的官方中文维基:http://wiki.codemongers.com/NginxChs
1.        安装:
2.       
rpm -Uvh http://download.fedora.redhat.co ... ease-5-2.noarch.rpm

yum install -y nginx php php-cli php-common php-pdo rrdtool-php  gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel lighttpd-fastcgi pcre pcre-devel

以cgi方式的php,安装lighttpd是为了得到启动fastcgi进程,nginx是通过调用fastcgi来解析PHP的,安装NGINX是一部分,然后安装PHP也是一部分,然后将nginx跟fastcgi连起来就行了。PHP5的CGI方式的一大优势是内置了FastCGI的支持,只需指明绑定的地址和端口参数便可以以FastCGI的方式运行,如下:
php-cgi -b 127.0.0.1:9000  如何配置其与nginx一起运行呢?

2.配置:
安装后,NGINX的网站目录位于:
/usr/share/nginx/html
NGINX的配置文件位于:
/etc/nginx/ nginx.conf

nginx -t              测试配置文件
nginx -v             查看相关版本

配置Nginx的PHP FastCGI, 为FastCGI模块设置了基本的环境变量
vi /etc/nginx/fastcgi.conf

输入:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;

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_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $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 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;

3./////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
接下来安装lighthttp以得到spawn-fcgi以此来控制php-cgi进程运行:

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -u nginx -g nginx -f /usr/bin/php-cgi

参数含义如下
-f <fcgiapp> 指定调用FastCGI的进程的执行程序位置,根据系统上所装的PHP的情况具体设置
-a <addr> 绑定到地址addr
-p <port> 绑定到端口port
-s <path> 绑定到unix socket的路径path
-C <childs> 指定产生的FastCGI的进程数,默认为5(仅用于PHP)
-P <path> 指定产生的进程的PID文件路径
-u和-g FastCGI使用什么身份(-u 用户 -g 用户组)运行,Ubuntu下可以使用www-data,其他的根据情况配置,如nobody、apache等

service nginx start

默认情况下。NGINX是可以开启静态页面,但如何开启PHP。还是要在/etc/nginx/nginx.php设置的。
    各位可以参考我的配置前后的截图(呵呵,研究下,有些参数是可以改变的。要举一返三吧):
修改前: 修改后: 保存更改。(  去除105 ----111行的#号,把110行的fastcgi_params改为/etc/nginx/fastcgi.conf,删除109行)
105         #    location ~ \.php$ {
    106         #    root           html;
    107         #    fastcgi_pass   127.0.0.1:9000;
    108         #    fastcgi_index  index.php;
    109         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    110         #    include        fastcgi_params;
    111         #}

然后service nginx restart便可了

11、配置虚拟主机
在APACHE上配置虚拟主机。想来各位都有一定的体验。那如何在NGINX中实现呢?
[root@nginx-freetds html]# vi /etc/nginx/nginx.conf

把下面这段加在最后一个}之前:

server {
        listen       80;
        server_name  bbs.xue360.com;
        location / {
            root   /usr/share/nginx/html/bbs;
            index  index.php index.html;
        }
        error_page  404              /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/share/nginx/html;
        }
        location ~ \.php$ {
            root           html/bbs/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        /etc/nginx/fastcgi.conf;
        }
}

论坛徽章:
0
2 [报告]
发表于 2009-05-25 23:17 |只看该作者
收藏
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP