首頁  >  文章  >  運維  >  詳解Nginx設定檔nginx.conf

詳解Nginx設定檔nginx.conf

巴扎黑
巴扎黑原創
2017-08-22 13:52:101675瀏覽

#定義Nginx運行的使用者和使用者群組

user www www;

#nginx進程數,建議設定為等於CPU總核心數。

worker_processes 8;

#全域錯誤日誌定義類型,[ debug | info | notice | warn | error | crit ]

error_log /var/log/nginx/error .log info;

#程式檔案

pid /var/run/nginx.pid;

#一個nginx程式開啟的最多檔案描述符數目,理論值應該是最多開啟檔案數(系統的值ulimit -n)與nginx進程數相除,但是nginx分配請求並不均勻,所以建議與ulimit -n的值保持一致。

worker_rlimit_nofile 65535;

#工作模式與連結數上限

events

{

    #參考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; epoll模型是Linux 2.6以上版本內核中的高效能網路I/O模型,如果跑在FreeBSD上面,就用kqueue模型。

    use epoll;

    #單一行程最大連線數(最大連線數=連線數*程序數)

    worker_connections 65535;

}

設定http伺服器

http

{

    include mime.types; #檔案副檔名與檔案類型對應表

    default_type application/octet-stream; #預設檔案類型

    #charset utf-8; #預設編碼

    server_names_hash_bucket_size 128; #伺服器名稱的hash資料表大小

## ; #上傳檔案大小限制

    large_client_header_buffers 4 64k; #設定請求緩

    client_max_body_size 8m; #設定請求緩

##    sendfile on; sendfile指令指定nginx是否呼叫sendfile函數來輸出文件,對於普通應用設為on,如果用來進行下載等應用磁碟IO重負載應用,可設定為off,以平衡磁碟與網路I/O處理速度,降低系統的負載。注意:如果圖片顯示不正常把這個改成off。

    autoindex on; #開啟目錄清單訪問,適當下載伺服器,預設為關閉。

    tcp_nopush on; #防止網絡阻塞

    tcp_nodelay on; #防止網絡阻塞

    keepalive_timeout 120; #長連接超時時間,單位是秒

#FastCGI相關參數是為了改善網站的效能:減少資源佔用,提高存取速度。下面參數看字面意思都能理解。

    fastcgi_connect_timeout 300;

    fastcgi_send_timeout 300;

    fastcgi_read_timeout 300;

##  _.. 4 64k;

    fastcgi_busy_buffers_size 128k;

    fastcgi_temp_file_write_size 128k;

    #gzip模組設定

## #最小壓縮檔案大小

    gzip_buffers 4 16k; #壓縮緩衝區

    gzip_http_version 1.0; #壓縮版本(預設1.1,前端若是squid2.5請使用1.0)## #pipdp. ; #壓縮等級

    gzip_types text/plain application/x-javascript text/css application/xml;

    #壓縮類型,預設就已經包含text/html,所以就不用再寫了,寫上去也不會有問題,但會有一個warn。

    gzip_vary on;

    #limit_zone crawler $binary_remote_addr 10m; #開啟限制IP連線數的時候需要使用

    upstream blog.ha97.

        #upstream的負載平衡,weight是權重,可依機器配置定義權重。 weigth參數表示權值,權值越高被分配到的幾率越大。

        server 192.168.80.121:80 weight=3;

        server 192.168.80.122:80 weight=2;##192.168.80.122:80 weight=2;##121 weight=3;

    }

    #虛擬主機的設定

    server{

    

#        #1

#        #網域可以有多個,用空格隔開

        server_name www.pythontab.com;

      #  index index.html index.htm index.php;##htm #        root /data/www/pythontab;

        location ~ .*.(php|php5)?$

        {

#o#  0.# 

#            fastcgi_index index.php;

            include fastcgi.conf;

##"  cation ~ .*.(gif |jpg|jpeg|png|bmp|swf)$

        {

            expires 10d;

        }

        #JS和CSS緩存時間設置

        location ~ .*.(js|css)? $

        {

#            expires 1h;

        }

## $remote_user [ $time_local] "$request" '

        '$status $body_bytes_sent "$http_referer" '

        '"$http_user_agent" $http_x_forwarded_for';的存取日誌

        access_log /var/log/nginx/pythontab.log access;

        #對"/" 啟用反向代理

        #對"/" 啟用反向代理

 ##            proxy_pass http://127.0.0.1:8888;

            proxy_刪除            #後端的Web伺服器可以透過X-Forwarded-For取得使用者真實IP

            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            #以下是一些反向代理的設定值。

            proxy_set_header Host $host;

            client_max_body_size 10m  位元組要求的最大單一檔案數# 10m k; #緩衝區代理程式緩衝用戶端請求的最大位元組數,

            proxy_connect_timeout 90; #nginx跟後端伺服器連線逾時時間(代理連線逾時)

         傳輸逾時)

         傳輸逾時)

         傳輸時間 pro

            proxy_read_timeout 90; #連線成功後,後端伺服器回應時間(代理接收逾時)

            proxy_buffer_size#            proxy_buffer_size#            proxy_buffer_size 4k; #設定吧

#            proxy_buffers 4 32k; #proxy_buffers緩衝區,網頁平均在32k以下的設定

               proxy_temp_file_write_size 64k;

            #設定快取資料夾大小,大於這個值,將從upstream伺服器傳送

        }

         # /NginxStatus {

            stub_status on;

            access_log on;

cgin  #     auth_basic_user_file conf/htpasswd;

            # htpasswd檔案的內容可以用apache提供的htpasswd工具來產生。

        }

        #本地動靜分離反向代理設定

        #所有jsp的頁面交由 tomcat或 |jspx|do)?$ {

            proxy_set_header Host $host;

            proxy_set_header X-Real-IP $remote_addr. ed-For $proxy_add_x_forwarded_for;

            proxy_pass http://127.0.0.1:8080;

        }

        #所有靜態檔案由   }

     ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)${ 

            expires 15d; 

        }

##        location ~ .* #        }

    }

}

以上是詳解Nginx設定檔nginx.conf的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn