美文网首页
记一份自己的nginx配置文件

记一份自己的nginx配置文件

作者: 鸟它鸟 | 来源:发表于2018-12-19 19:34 被阅读0次

    nginx.conf部分

    ######################
    #### sys-router
    #######################
    
    worker_rlimit_nofile 204800;
    worker_processes auto;
    worker_cpu_affinity auto;
    
    error_log  logs/error.log  error;
    pid        logs/nginx.pid;
    
    events {
        worker_connections  204800;
    }
    
    http {
        include       mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '{'
                          '"remote_addr":"$remote_addr","upstream_addr":"$upstream_addr",'
                          '"time_iso8601":"$time_iso8601","msec":"$msec",'
                          '"request_time":$request_time,"upstream_response_time":$upstream_response_time,'
                          '"status":"$status","upstream_status":"$upstream_status",'
                          '"http_user_agent":"$http_user_agent","server_protocol":"$server_protocol",'
                          '"server_name":"$server_name","server_port":"$server_port",'
                          '"request_method":"$request_method","uri":"$uri",'
                          '"request_uri":"$request_uri","request_body":[$request_body]'
                          '}';
    
        access_log  logs/${server_name}.access.log  main;
    
        sendfile        on;
        tcp_nopush      on;
        tcp_nodelay     on;
    
        keepalive_timeout  180;
    
        include server_conf/*.conf;
        include upstream_conf/*.conf;
    
    }
    
    

    server_conf的default配置

    server {
       listen 80 default_server;
       location / {
           return 404;
       }
    }
    

    server_conf的站点配置部分

    server {
           listen 80;
           server_name test.com;
           proxy_read_timeout 600;
           proxy_send_timeout 600;
           proxy_set_header X-Real-IP $remote_addr;
    
           location / {
                    if ( $query_string ~* ^(.*)us\b(.*)$ ) {
                            proxy_pass http://upstream_conf1;
                            break;
                    }
                    proxy_pass http://upstream_conf2;
            }
    
           location /users/info {
                    if ( $query_string ~* ^(.*)us\b(.*)$ ) {
                            proxy_pass http://upstream_conf1;
                            break;
                    }
                    proxy_pass http://upstream_conf2;
            }
    }
    

    日志切割部分

    #!/bin/bash
    #Rotate the Nginx logs to prevent a single logfile from consuming too much disk space. 
    
    CONF_PATC=/home/nginx-sys-router/conf/server_conf
    LOGS_PATH=/home/nginx-sys-router/logs
    YESTERDAY=$(date -d "yesterday" +%Y-%m-%d)
    #mv ${LOGS_PATH}/access.log ${LOGS_PATH}/access_${YESTERDAY}.log
    #mv ${LOGS_PATH}/error.log ${LOGS_PATH}/error_${YESTERDAY}.log
    
    for server_name_conf in `ls ${CONF_PATC}`
    do  
        servername=`echo "${server_name_conf}"|awk -F ".conf" {'print $1'}`
        servernamelog="${LOGS_PATH}/${servername}.access.log"
        if [ ! -f "${servernamelog}" ]
        then
            continue 1
        fi
        servernamelog_backup="${LOGS_PATH}/${servername}_${YESTERDAY}.access.log"
        mv ${servernamelog} ${servernamelog_backup}
    done
        
    kill -USR1 $(cat ${LOGS_PATH}/nginx.pid)
    
    

    相关文章

      网友评论

          本文标题:记一份自己的nginx配置文件

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