nginx

作者: 天生顽皮 | 来源:发表于2021-04-28 20:11 被阅读0次

    nginx实战过程

    1.安装依赖包

    *nginx安装依赖gcc、openssl-devel、prce-devel和zlib-devel软件库
    *Prce全程(Perl Compatible Regular Expressions),中文perl兼容正则表达式,[pcre官方站点](http://www.pcre.org/)
    
    
    1.yum  install  -y  prce  prce-devel
    2.yum  install  -y  openss  openssl-devel
    

    2.开始编译

    使用./configure --help查看各个模块的使用情况,使用--without-http_ssi_module的方式关闭不需要的模块。可以使用--with-http_perl_modules方式安装需要的模块

    3.编译命令

    1.tar -zxf nginx-1.10.1.tar.gz 
    2.cd nginx-1.10.1/
    3.  ./configure --prefix=/data/nginx-1.10.1 --user=nginx --group=nginx  --with-http_ssl_module  --with-http_stub_status_module
    4.
    5.useradd nginx -M -s /sbin/nologin 
    6.make && make install 
    7.ln -s /data/nginx-1.10.1 /data/nginx
    

    4.测试nginx配置文件是否正常

    1./data/nginx/sbin/nginx -t 
    2.nginx: the configuration file /data/nginx-1.10.1/conf/nginx.conf syntax is ok
    3.nginx: configuration file /data/nginx-1.10.1/conf/nginx.conf test is successful
    

    5.启动nginx服务器

    1./data/nginx/sbin/nginx  -t  ##检查配置文件
    2./data/nginx/sbin/nginx      ##确定nginx服务
    3.netstat -lntup |grep nginx      ## 检查进程是否正常
    4.curl http://localhost           ## 确认结果
    
    /data/nginx/sbin/nginx -V 查看已经编译的参数

    使用kill命令操作nginx。格式:kill -信号 PID

    信号名称

    ***TERM,INT 快速关闭
    ***QUIT 优雅的关闭,保持吸纳有的客户端连接
    ***HUP 重启应用新的配置文件
    ***USR1 重新打开日志文件
    ***USR2 升级程序
    ***WINCH 优雅的关闭工作进程

    例子:

    1.kill -QUIT  `cat /data/nginx/nginx.pid`
    2.kill -HUP `cat /data/nginx/nginx.pid`
    

    6.nginx配置文件

    配置基本文件

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        server {
            listen       80;
            server_name  localhost;
            location / {
                root   html;
                index  index.html index.htm;
            }
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
        }
    }
    ### 测试配置文件是否正常
    shell> /data/nginx/sbin/nginx -t 
    nginx: the configuration file /data/nginx-1.10.3/conf/nginx.conf syntax is ok
    nginx: configuration file /data/nginx-1.10.3/conf/nginx.conf test is successful
    shell> curl -I http://localhost
    HTTP/1.1 200 OK
    

    7.nginx监控

    开启nginx服务

    1.开启状态页
    #设定查看Nginx状态的地址   
    location /status {  
      stub_status on;       #表示开启stubStatus的工作状态统计功能。
      access_log off;       #access_log off; 关闭access_log 日志记录功能。
      #auth_basic "status";                             #auth_basic 是nginx的一种认证机制。
      #auth_basic_user_file conf/htpasswd;  #用来指定密码文件的位置。
    }
    
    2.配置登陆密码
    yum install -y httpd-tools
    /usr/local/apache/bin/htpasswd -c /data/nginx/conf/htpasswd biglittleant 
    New password:
    

    完成后会在/data/nginx/conf/目录下生成htpasswd文件。

    3.访问URL
    curl http://127.0.0.1/status
    
    Active connections:  1
    server accepts handled requests
     16 16 18
    Reading: 0 Writing: 1 Waiting: 0
    
    #active connections – 活跃的连接数量
    #server accepts handled requests — 总共处理了16个连接 , 成功创建16次握手, 总共处理了18个请求
    #Reading — 读取客户端的连接数: Writing 响应数据到客户端的数量; Waiting 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.
    

    相关文章

      网友评论

          本文标题:nginx

          本文链接:https://www.haomeiwen.com/subject/wehbrltx.html