zoukankan      html  css  js  c++  java
  • nginx

    安装nginx

    先安装gccopenssl-develprce-develzlibzlib-devel软件库;

    1.安装nginx所需pcre-devel的库

    安装pcre库是为了nginx支持http rewrite模块

    #tar -zxvf  pcre-8.02.tar.gz

    #cd pcre-8.02

    #./configure  #make &&make install

    2.开始安装nginx

    使用什么模块就开启什么模块;--without-http_ssi_module关闭,如需要http_perl模块;--with-http_perl_module方式安装

    # tar -zxvf nginx-0.7.69.tar.gz 

    [root@localhost nginx-0.7.69]# ./configure --with-http_stub_status_module --prefix=/opt/nginx

    [root@localhost nginx-0.7.69]# make &&make install

    3.全局配置文件

    user  nobody nobody;

    worker_processes  4;

    #error_log  logs/error.log ;

    #error_log  logs/error.log  notice;

    #error_log  logs/error.log  info;

    #pid        logs/nginx.pid;

    worker_rlimit_nofile 65535

    google_perftools_profiles /tmp/tcmalloc;

    events {

    use epoll

        worker_connections  65536;

    }

    -------(还有一个模块没配置)

    5.httpGzip模块配置

    配置nginxhttpGzip这个模块支持在线实时压缩输出数据流。要查看是否安装了此模块,需要使用下面的命令:

    [root@localhost nginx]# /opt/nginx/sbin/nginx -V

    nginx version: nginx/0.7.69

    configure arguments: --with-google_perftools_module --with-http_stub_status_module --prefix=/opt/nginx

    下面是HttpGzip模块在Nginx配置中的相关属性设置:

    gzip  on;  开启gzip模块

    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 application/xml;  

    gzip_vary  on; 

    ----------(还有三个模块没配置)

    7.URL匹配配置

    URL地址匹配是Nginx配置中最灵活的部分。 location支持正则表达式匹配,也支持条件判断匹配,用户可以通过location指令实现Nginx对动、静态网页的过滤处理。以下这段设置是通过location指令来对网页URL进行分析处理,所有扩展名为.gif、.jpg、.jpeg、.png、.bmp、.swf的静态文件都交给Nginx处理,而expires用来指定静态文件的过期时间,这里是30天。

    location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$  {  

                       root    /web/wwwroot/www.ixdba.net;  

                        expires 30d;  

           } 

     

    8.配置与调试nginx

    以下这段设置是将upload和html下的所有文件都交给Nginx来处理,当然,upload和html目录包含在/web/wwwroot/www.ixdba.net目录中。

    location ~ ^/(upload|html)/  {  

                    root    /web/wwwroot/www.ixdba.net;  

                    expires 30d;  

    在最后这段设置中,location是对此虚拟主机下动态网页的过滤处理,也就是将所有以.jsp为后缀的文件都交给本机的8080端口处理。location ~ .*.jsp$ {  

                index index.jsp;  

                proxy_pass http://localhost:8080;  

              } 

    9. StubStatus模块配置

    StubStatus模块能够获取Nginx自上次启动以来的工作状态,此模块非核心模块,需要在Nginx编译安装时手工指定才能使用。

    以下指令指定启用获取Nginx工作状态的功能。

          location /NginxStatus {  

                  stub_status     on;  

        access_log             logs/NginxStatus.log;  

               auth_basic             "NginxStatus";  

             #     auth_basic_user_file    ../htpasswd;  

           } 

     


    10.ginx基本信息检查

    (1)检查Nginx配置文件的正确性

    [root@localhost nginx]# /opt/nginx/sbin/nginx -t -c /opt/nginx/conf/nginx.conf

    the configuration file /opt/nginx/conf/nginx.conf syntax is ok

    configuration file /opt/nginx/conf/nginx.conf test is successful

    说明配置文件正确。

    2)显示Nginx的版本以及相关编译信息

    在命令行执行以下命令可以显示安装Nginx的版本信息:

    /opt/nginx/sbin/nginx -v 

     执行以下命令可显示安装的Nginx版本和相关编译信息:/opt/nginx/sbin/nginx -V 

    上述命令不但显示Nginx的版本信息,同时显示Nginx在编译时指定的相关模块信息。

    启动nginx

    [root@localhost nginx]# /opt/nginx/sbin/nginx 

    [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)

    [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)

    [root@localhost nginx]# ps -ef |grep nginx

    root     22390     1  0 21:45 ?        00:00:00 nginx: master process /opt/nginx/sbin/nginx

    nobody   22391 22390  0 21:45 ?        00:00:00 nginx: worker process

    nobody   22392 22390  0 21:45 ?        00:00:00 nginx: worker process

    nobody   22393 22390  0 21:45 ?        00:00:00 nginx: worker process

    nobody   22394 22390  0 21:45 ?        00:00:00 nginx: worker process

    pid是Nginx的进程号,可以通过如下两个命令获取:

    [root@localhost logs]# ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'

    22390

    [root@localhost logs]# cat /opt/nginx/logs/nginx.pid 

    22390

    关闭nginx

    [root@localhost logs]# /opt/nginx/sbin/nginx -s stop

    11.安装libunwind库

    [root@localhost home]#tar zxvf libunwind-0.99-alpha.tar.gz  

    [root@localhost home]# cd libunwind-0.99-alpha/  

    [root@localhost libunwind-0.99-alpha]#CFLAGS=-fPIC ./configure  

    [root@localhost libunwind-0.99-alpha]#make CFLAGS=-fPIC  

    [root@localhost libunwind-0.99-alpha]#make CFLAGS=-fPIC install 

    12.安装google-perftools

    [root@localhost home]#tar zxvf google-perftools-1.8.tar.gz  

    [root@localhost home]#cd google-perftools-1.8/  

    [root@localhost google-perftools-1.8]# ./configure  

    [root@localhost google-perftools-1.8]#make && make install  

     [root@localhost google-perftools-1.8]# echo "/usr/local/lib" >/etc/ld.so.conf.d/usr_local_lib.conf 

    [root@localhost google-perftools-1.8]# ldconfig 

    google-perftools安装完成。

    13.重新编译Nginx

    为了使Nginx支持google-perftools,需要在安装过程中添加“–with-google_perftools_module”选项重新编译Nginx。

    安装代码如:

    [root@localhost nginx-0.7.69]#./configure --prefix=/opt/nginx   --with-google_perftools_module  --with-http_stub_status_module  

    14.为google-perftools添加线程目录

    创建一个线程目录,这里将文件放在/tmp/tcmalloc下。操作如下:

    [root@localhost home]#mkdir /tmp/tcmalloc  

    [root@localhost home]#chmod 0777 /tmp/tcmalloc 

    15.修改Nginx主配置文件

    修改nginx.conf文件,在pid这行的下面添加如下代码:

    #pid        logs/nginx.pid;  

    google_perftools_profiles /tmp/tcmalloc; 

    接着,重启Nginx即可完成google-perftools的加载。

    验证:

    [root@localhost nginx-0.7.69]# lsof -n |grep tcmalloc

    nginx     22814    nobody   10w      REG        8,2        0     680759 /tmp/tcmalloc.22814

    nginx     22815    nobody   12w      REG        8,2        0     680763 /tmp/tcmalloc.22815

    nginx     22816    nobody   14w      REG        8,2        0     680760 /tmp/tcmalloc.22816

    nginx     22817    nobody   16w      REG        8,2        0     680761 /tmp/tcmalloc.22817

     



     
    由于在Nginx配置文件中设置worker_processes的值为4,因此开启了4个Nginx线程,每个线程会有一行记录。每个线程文件后面的数字值就是启动的Nginx的pid值。

    至此,利用TCMalloc优化Nginx的操作完成。

  • 相关阅读:
    RAD Studio XE2/XE3 官方 ISO 下载地址 (20120905更新)
    delphi调用webservice接口时返回result element expected的解决办法
    delphi 线程使用
    App数据格式之解析Json
    android 改变文字的大小和字体
    [最新]Visual Assist X 破解版下载(10.7.1929_Patched)
    [解决]Win7 操作系统不能安装VMware
    android 获取已安装程序列表
    unidac 执行Execute后取得受影响行数。
    android 获取所有传感器数据
  • 原文地址:https://www.cnblogs.com/wangyao3568/p/7675883.html
Copyright © 2011-2022 走看看