zoukankan      html  css  js  c++  java
  • nginx笔记.

    安装:

    依赖的软件包:

    gcc gcc-c++ autoconf automake
    zlib zlib-devel openssl opensll-devel pcre pcre-devel

    到官方网站上下载nginx包:

    解压:

    tar -zxf nginx-x.x.tar.gz

    安装三步走:./configure------- make------make install

    ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx 
    --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid 
    --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module 
    --with-http_gzip_static_module --with-http_ssl_module --http-log-path=/var/log/nginx/access.log 
    --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/
     --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ 
    [root@localhost ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf   启动nginx

    查看nginx是否启动:

    [root@localhost ~]# lsof -i:80
    COMMAND  PID  USER   FD   TYPE DEVICE SIZE NODE NAME
    nginx   7802  root    6u  IPv4  22039       TCP *:http (LISTEN)
    nginx   7803 nginx    6u  IPv4  22039       TCP *:http (LISTEN)
    [root@localhost ~]# 
    
    [root@localhost ~]# 
    [root@localhost ~]# ps -ef | grep nginx
    root      7802     1  0 09:36 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf master#主进程
    nginx     7803  7802  0 09:36 ?        00:00:00 nginx: worker process               #子进程                              
    root      7807  3696  0 09:36 pts/3    00:00:00 grep nginx
    [root@localhost ~]#
    /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf #检查配置文件的正确性。

    nginx.conf 配置文件定义:

    user  www www;       #使用的用户和组
    worker_processes  2; #指衍生进程数(一般设置为cpu总核数的两倍)。
    
    
    events {
        worker_connections  1024; #允许最大连接数
    }
    
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        server_names_hash_bucket_size 128;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
    #-------------------------------------------------
    #设置客户端能够上传的文件大小。
        client_max_body_size 8m;
    
    #-------------------------------------------------
    
        sendfile        on;
        tcp_nopush        on;
    
    
        keepalive_timeout  65;
        tcp_nodelay    on;
    
    
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 128k;
    #----------------------------------------
    #开启gzip压缩
        gzip on;
        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;
    #----------------------------------------
            server {
            listen       80;
            server_name  www.nimei.com;
            index  index.html index.htm index.php;
            root /data0/htdocs;
            location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
            {
              expires       30d;
            }
            location ~ .*.(js|css)?$
            {
              expires       1h;
            }
            log_format access '$remote_addr - $remote_user [$time_local] "$request"'
                              '$status $body_bytes_sent "$http_referer"'
                              '"$http_user_agent" $http_x_forwarded_for';
            access_log /data1/logs/acess.log access;
    
            }
            server {
    
            listen       80;    #虚拟主机监听的端口
            server_name  www.nimei1.com;#虚拟主机域名或IP
            access_log /data1/logs/vm1_access.log combined; 日志目录
    
            location /
                    {
            index  index.html index.htm;    #默认解析页面
            root /data0/htdocs/nimei1;    #网站源码路径
                    }
                    }
    }

    1.从容停止nginx(nginx启动停止由其pid决定):

    kill -QUIT nginx主进程号
    kill -QUIT 7802 或者 kill -QUIT `cat /var/run/nginx/nginx.pid`

    2.快速停止nginx:

    kill -TERM ngixID 或者 kill -INT nginxID   nginxID-----主进程号
    [root@localhost ~]# kill -TERM 7886
    [root@localhost ~]# 
    [root@localhost ~]# ps -ef | grep nginx
    root      7900  3696  0 10:04 pts/3    00:00:00 grep nginx

    3.强制停止nginx:

    pkill -9 nginx

    4.平滑启动nginx:

    kill -HUP nginxID

    Nginx信号控制说明:

    TERM,INT 快速关闭nginx
    QUIT 从容关闭;
    HUP 平滑启动;
    USR1 重新打开日志文件(日志切割很有用)
    USR2  平滑升级可执行程序。
    WINCH  从容关闭工作。升级新版本关闭旧版本时用WINCH。

    检查nginx配置文件的正确与否:

    /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
    [root@localhost ~]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
    the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
    configuration file /usr/local/nginx/conf/nginx.conf test is successful
    [root@localhost ~]#

     《未完待续》--------

  • 相关阅读:
    linux下的crontab定时执行任务命令详解
    494. Target Sum
    347. Top K Frequent Elements
    5. Longest Palindromic Substring
    时间复杂度计算方法
    62. Unique Paths
    54. Spiral Matrix && 59. Spiral Matrix II
    57. Insert Interval
    53. Maximum Subarray
    42.Trapping rain water
  • 原文地址:https://www.cnblogs.com/osxlinux/p/3302454.html
Copyright © 2011-2022 走看看