centos 编译安装nginx

一、确保系统已经安装了软件编译安装工具:gcc  gcc-c++  make,如果没有安装运行安装:

yum install gcc  gcc-c++  make

工具介绍:

gcc  C编译器

gcc-c++  c++编译器

make  编译工具,解释makefile文件的规则来编译复杂软件

二、为了支持rewrite功能,我们需要安装pcre

yum install pcre*

三、需要ssl的支持,如果不需要ssl支持,请跳过这一步

yum install openssl*

四、安装nginx;下载nginx源码包,这里我下载的是:nginx-1.8.1

#解压nginx-1.8.1
tar -xzvf nginx-1.8.1
cd nginx-1.8.1

#配置,编译,并安装(指定了安装路径为:/usr/local/nginx)
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
make
make install

 配置nginx支持php,编辑nginx配置文件nginx.cfg:

 

        location / {
            root   html;
            index  index.html index.htm index.php;    #添加index.php
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
            root           /usr/local/nginx/html;    #nginx网址根目录
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;     #SCRIPT_FILENAME后面是nginx根目录
            include        fastcgi_params;
        }

到此nginx安装完成,启动nginx:

/usr/local/sbin/nginx

 在本机浏览器访问 localhost:80,即可看到nginx的默认页面

 参考地址:http://www.ttlsa.com/nginx/nginx-install-on-linux/

posted @ 2017-12-24 11:45  远洪  阅读(137)  评论(0编辑  收藏  举报