nginx-生產(chǎn)環(huán)境配置

user nginx;

#工作進(jìn)程數(shù),建議設(shè)置為CPU的總核數(shù)
worker_processes 4;

#全局錯(cuò)誤日志定義類(lèi)型,日志等級(jí)從低到高依次為:
#debug | info | notice | warn | error | crit

error_log /mydata/nginx_log/error.log info;

#記錄主進(jìn)程ID的文件
pid /mydata/nginx_log/nginx.pid;

#指定進(jìn)程可以打開(kāi)的最大描述符數(shù)目
worker_rlimit_nofile 204800;

events {
    use epoll;
    
   #單個(gè)進(jìn)程最大連接數(shù):連接數(shù)*進(jìn)程數(shù) 65535
    worker_connections 204800;
}

#設(shè)定http服務(wù)器,利用它的反向代理功能提供負(fù)載均衡支持
http {
    #文件擴(kuò)展名與文件類(lèi)型映射表
    include /etc/nginx/mime.types;

    #默認(rèn)文件類(lèi)型
    default_type application/octet-stream;

    charset utf-8;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 2k;
    large_client_header_buffers 4 4k;
    client_max_body_size 8m;

    #為打開(kāi)文件指定緩存
    open_file_cache max=65535 inactive=60s;

    #這個(gè)是指多長(zhǎng)時(shí)間檢查一次緩存的有效信息。
    #語(yǔ)法:open_file_cache_valid time 默認(rèn)值:open_file_cache_valid 60 使用字段:http, server, location 這個(gè)指令指定了何時(shí)需要檢查open_file_cache中緩存項(xiàng)目的有效信息.
    open_file_cache_valid 80s;

    #open_file_cache指令中的inactive參數(shù)時(shí)間內(nèi)文件的最少使用次數(shù),如果超過(guò)這個(gè)數(shù)字,文件描述符一直是在緩存中打開(kāi)的,如上例,如果有一個(gè)文件在inactive時(shí)間內(nèi)一次沒(méi)被使用,它將被移除。
    #語(yǔ)法:open_file_cache_min_uses number 默認(rèn)值:open_file_cache_min_uses 1 使用字段:http, server, location  這個(gè)指令指定了在open_file_cache指令無(wú)效的參數(shù)中一定的時(shí)間范圍內(nèi)可以使用的最小文
件數(shù),如果使用更大的值,文件描述符在cache中總是打開(kāi)狀態(tài).
    open_file_cache_min_uses 1;

    #語(yǔ)法:open_file_cache_errors on | off 默認(rèn)值:open_file_cache_errors off 使用字段:http, server, location 這個(gè)指令指定是否在搜索一個(gè)文件是記錄cache錯(cuò)誤.
    open_file_cache_errors on;

     #日志格式
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"'
                      '$request_body';

    #access log 記錄了哪些用戶,哪些頁(yè)面以及用戶瀏覽器、ip和其他的訪問(wèn)信息
    access_log /mydata/nginx_log/access.log main;

    #隱藏ngnix版本號(hào)
    server_tokens off;

#sendfile指令指定 nginx 是否調(diào)用sendfile 函數(shù)(zero copy 方式)來(lái)輸出文件,對(duì)于普通應(yīng)用,必須設(shè)為on。如果用來(lái)進(jìn)行下載等應(yīng)用磁盤(pán)IO重負(fù)載應(yīng)用,可設(shè)置為off,以平衡磁盤(pán)與網(wǎng)絡(luò)IO處理速度,降
低系統(tǒng)uptime。
    sendfile on;

    #長(zhǎng)連接超時(shí)時(shí)間,單位是秒
    keepalive_timeout 120;

    #gzip模塊設(shè)置
    gzip on; #開(kāi)啟gzip壓縮輸出
    gzip_min_length 1k;    #最小壓縮文件大小
    gzip_buffers 4 16k;    #壓縮緩沖區(qū)
    gzip_http_version 1.0;    #壓縮版本(默認(rèn)1.1,前端如果是squid2.5請(qǐng)使用1.0)
    gzip_comp_level 2;    #壓縮等級(jí)
    gzip_types text/plain application/x-javascript text/css application/xml;    #壓縮類(lèi)型,默認(rèn)就已經(jīng)包含textml,所以下面就不用再寫(xiě)了,寫(xiě)上去也不會(huì)有問(wèn)題,但是會(huì)有一個(gè)warn。
    gzip_vary on;

   server {
        listen 80;
        server_name xxxxx;

        access_log /mydata/nginx_log/xx.log main;

        location / {
                proxy_pass http://localhost:8080;
                proxy_set_header Host $host;
                proxy_redirect off;
                proxy_set_header   X-Real-IP   $remote_addr;
                proxy_http_version 1.1;
                proxy_set_header Connection "";
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

    #php-fpm
    server {
        listen 80;
        server_name xx;

        access_log /mydata/nginx_log/xx.log main;

        location / {
            root /xx;
            index index.php;
        }

        location ~ \.php$ {
            root /xx;

            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }   
}
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容