nginx profile description

Keywords: Nginx PHP Javascript network

nginx.conf

user  www www; # Nginx's worker processes run users and user groups

worker_processes 4; # Number of startup processes, usually set equal to the number of CPUs
#worker_processes auto;

#The following parameters specify which cpu is assigned to which process, generally speaking, there is no special specification. If you have to set it, use 0 and 1 to specify the allocation method
#In this way, 1-4 processes are assigned a separate core to run, and the fifth process is randomly assigned.
#worker_processes 4     #4 core CPU 
#worker_cpu_affinity 0001 0010 0100 1000

error_log  /home/wwwlogs/nginx_error.log  crit; # Define global error log definition type, [debug|info|notice|warn|crit]

pid        /usr/local/nginx/logs/nginx.pid; # PID file

#Specifies the value for maximum file descriptors that can be opened by this process.
# The theoretical value of the maximum number of file descriptors opened by a nginx process should be the maximum number of open files (ulimit-n) divided by the number of nginx processes, but the allocation request of nginx is not so uniform, so it is better to keep the same value as ulimit-n.
worker_rlimit_nofile 51200;

# Working mode and maximum number of connections
events
    {
        # Use [kqueue | rtsig | epoll | / dev / poll | select | poll]; epoll model is a high-performance network I/O model in the kernel of Linux 2.6 and above. If running on FreeBSD, use kqueue model.
        use epoll; 
        worker_connections 51200; # Maximum number of concurrent links for a single background worker process
        #worker working mode: serial (reduce load to some extent, but turn off parallel mode when server throughput is large)
        multi_accept on;
    }

http
    {
        #File extension and file type mapping table
        include       mime.types;
        #Default file type
        default_type  application/octet-stream;
        //hash table size of server name
        server_names_hash_bucket_size 128;
        #Specifies the hearbuffer size from the client request header
        client_header_buffer_size 32k;
        #Specifies the maximum number and size of caches for larger headers in client requests.
        large_client_header_buffers 4 32k;
        #Maximum number of bytes of a single file requested by the client
        client_max_body_size 50m;

        sendfile   on; #Turn on efficient transmission mode.
        #Prevent network congestion
        tcp_nopush on;

        keepalive_timeout 60; # Connection timeout in seconds

        tcp_nodelay on;

        #FastCGI related parameters are to improve the performance of the website: reduce resource occupation and improve the access speed.
        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 256k;

        gzip on; # Turn on gzip compression
        gzip_min_length  1k; #Minimum compressed file size
        gzip_buffers     4 16k; #Compress buffer
        gzip_http_version 1.1; #Compressed version (default 1.1, use 1.0 if front end is squid2.5)
        gzip_comp_level 2; #The higher the compression level 1-9 is, the better the compression effect is, and the broadband is saved, but the CPU consumption is large
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss; #The compression type already contains text/html by default, so there is no need to write any more below. There will be no problem in writing, but there will be a warn.
        #Front end cache servers cache compressed pages
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        #limit_conn_zone $binary_remote_addr zone=perip:10m;
        ##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

        server_tokens off;
        access_log off;
        # Define log format
        log_format up_head '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for" "deviceid: $http_deviceid"'
                        '"$request_body"  $upstream_response_time "$request_time"';


    include vhost/*.conf;
}

vhost/test.conf

server {
    listen 80;
    listen 443 ssl;
    server_name www.test.com;

    ssl_certificate      /nginx/conf/https/www.test.com.crt;
    ssl_certificate_key  /nginx/conf/https/www.test.com.key;
    root   /www/www.test.com;
    index  index.html index.htm index.php;

    location ~^/test.php {
          default_type    application/json;
          return 404 '{404}';
          access_log off;
    }

    location ~ ^/test/status(.*)$
    {
        default_type text/html;
        access_log /log/nginx/access/dot.log;
        return 200 '';
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    location ~\.php$ {
            # If sock is used, the value refers to unix:/var/run/php/php7.0-fpm.sock
            fastcgi_pass             unix:/tmp/php-cgi.sock;
            fastcgi_index            index.php;
            fastcgi_param            SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include                  fastcgi_params;
            access_log /log/nginx/access/access.log up_head;
     }

    #Static file
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
    }

    location ~ .*\.(js|css)?$
    {
        expires      12h;
    }

    location ~ /.well-known {
        allow all;
    }

    location ~ /\.
    {
        deny all;
    }

    error_log /log/nginx/error/error.log;
}

Define log format parameter description:

    #Define the format of the log. Define what to output later.
    #1. $remote ﹣ addr and $http ﹣ x ﹣ forwarded ﹣ for recording the ip address of the client;
    #2.$remote_user: used to record the client user name;
    #3.$time_local: used to record access time and time zone;
    #4.$request: the url and http protocol used to record the request;
    #5.$status: used to record the request status; 
    #6.$body_bytes_sent: records the size of the body content sent to the client;
    #7.$http_referer: used to record the links from that page;
    #8. $http ﹣ user ﹣ agent: record relevant information of client browser

Posted by lukeurtnowski on Tue, 31 Mar 2020 13:02:36 -0700