安装Nginx网络HTTP服务器(Linux) (2015-01-23)

来源:互联网 发布:怎么查淘宝店地址 编辑:程序博客网 时间:2024/05/06 03:51
第一步:安装依赖库

CentOS用这个

yum install make gcc pcre-devel zlib-devel openssl-devel git bison wget

 

Ubuntu用这个

sudo apt-get install gcc libpcre++-dev libssl-dev make git

 

第二步:下载所需nginx的扩展源码

mkdir -p /home/git/codecd /home/git/codegit clone https://github.com/yaoweibin/ngx_http_substitutions_filter_modulegit clone https://github.com/agentzh/sregexgit clone https://github.com/agentzh/replace-filter-nginx-module

 

 

第三步:安装sregex

cd /home/git/code/sregexmakemake install

 

 

第四步:到www.nginx.org官方下载最新稳定版

mkdir ~/downcd ~/downwget http://nginx.org/download/nginx-1.8.0.tar.gztar zxvf nginx-1.6.2.tar.gz

 

 

第五步:编译安装

cd ~/down/nginx-1.6.2./configure \--with-http_stub_status_module \--with-http_ssl_module \--with-http_spdy_module \--with-http_realip_module \--with-http_sub_module \--with-http_gzip_static_module \--with-ipv6 \--add-module=/home/git/code/ngx_http_substitutions_filter_module \--add-module=/home/git/code/replace-filter-nginx-module

执行编译安装

makemake install

 

 

 第六步:查看编译相关信息

/usr/local/nginx/sbin/nginx -V

如果看到下面的提示就对了

nginx version: nginx/1.6.2built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)TLS SNI support enabledconfigure arguments: --with-http_stub_status_module --with-http_ssl_module --with-http_spdy_module --with-http_realip_module --with-http_sub_module --with-http_gzip_static_module --with-ipv6 --add-module=/home/git/ngx_http_substitutions_filter_module --add-module=/home/git/replace-filter-nginx-module

 

 

第七步:启动与检查

当你执行下面语句时,没有任何返回,说明运行成功。

/usr/local/nginx/sbin/nginx

确定是否运行成功

netstat -anp |grep 80

如果结果中存在

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      712/nginx

说明成功了

再来看看712/nginx的具体路径

ps x |grep 712

如果结果是

  712 ?        Ss     0:00 nginx: master process /usr/local/nginx/sbin/nginx

可以看到路径/usr/local/nginx/sbin/nginx说明成功了

 

最后将

/usr/local/nginx/sbin/nginx

写入到

/etc/rc.local

让系统开机就自动启动nginx

 

 

 

 

最后说一些可能会出现的问题

/usr/local/nginx/sbin/nginx: error while loading shared libraries: libsregex.so.0: cannot open shared object file: No such file or directory

对于上面这种问题,可以用下面方法解决

ldd /usr/local/nginx/sbin/nginx

确定问题后,如果是32位系统执行

ln -s /usr/local/lib/libsregex.so.0 /lib

 如果是64位系统,执行

ln -s /usr/local/lib/libsregex.so.0 /lib64

 

 

 

关于配置PHP方面的

请编辑下面文件(推荐vi或vim)

/usr/local/nginx/conf/nginx.conf

1:找到下面一段文字,大概在65行(vi/vim编辑器的可以使用:65到达)

        #location ~ \.php$ {        #    root           html;        #    fastcgi_pass   127.0.0.1:9000;        #    fastcgi_index  index.php;        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;        #    include        fastcgi_params;        #}

将每一行前面的#符号都去掉

 2:将其中的

fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

改成

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

3:保存后,重新载入nginx配置文件

/usr/local/nginx/sbin/nginx -t/usr/local/nginx/sbin/nginx -s reload

4:创建phpinfo.php测试文件

/usr/local/nginx/html/phpinfo.php

 内容为

<?phpphpinfo();

5:运行php文件测试

http://127.0.0.1/phpinfo.php

请将127.0.0.1换成你服务器的IP地址,并在浏览器里打开查看。

 

 

配置参考

worker_processes 1;pid logs/nginx.pid;events{    worker_connections 1024;}http{    access_log off;    include mime.types;    sendfile on;    client_body_temp_path temp/client_body_temp;    fastcgi_temp_path temp/fastcgi_temp;    scgi_temp_path temp/scgi_temp;    uwsgi_temp_path temp/uwsgi_temp;    proxy_temp_path temp/proxy_temp;    server{        listen 0.0.0.0:80;        server_name www.baidu.com;        proxy_set_header Host www.baidu.com;        proxy_set_header X-Real-IP $remote_addr;        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;        location / {            proxy_pass http://www.baidu.com;        }    }    server{        listen 0.0.0.0:80 default;        root html;    }}

 

0 0
原创粉丝点击