nginx.conf配置說明
# 服務運行帳戶
#user gisapp;
user nobody;
# 如果你的 Nginx 是多個 CPU 和多核合愈,需要配置成多核的數(shù)量比較好
# worker_processes最多開啟8個萍歉,8個以上性能就不會再提升了,而且穩(wěn)定性會變的更低,因此8個進程夠用了
worker_processes? 8;
# 8核cpu,開啟8個進程,cpu有多少個核,就有幾位數(shù)戳杀,1代表內(nèi)核開啟叫倍,0代表內(nèi)核關閉
worker_cpu_affinity 10000000 01000000 00100000 00010000 00001000 00000100 00000010 00000001;?
# 如果 Nginx 服務很大的流量,增加最大可以打開的文件句柄還是很有用的豺瘤,因為默認只有 1024 個,可以使用 'ulimit -n' 看到當前系統(tǒng)中的設置
worker_rlimit_nofile 65535;
# 錯誤日志,不要隨意修改日志文件名稱路徑听诸,日志切割腳本需要同步修改
#error_log? logs/error.log;
#error_log? logs/error.log? notice;
#error_log? logs/error.log? info;
#error_log? /log/nginx_logs/proxy.error.log? crit;
# 進程編號文件坐求,不要隨意修改,服務重起和日志切割需要用到
pid? ? ? ? logs/nginx.pid;
events {
? ? #epoll是多路復用IO(I/O Multiplexing)中的一種方式,但是僅用于linux2.6以上內(nèi)核,可以大大提高nginx的性能
? ? use epoll;
? ? #單個后臺worker process進程的最大并發(fā)鏈接數(shù)
? ? worker_connections? 65535;
? ? # max_clients = worker_connections * worker_processes
}
http {
? ? include? ? ? mime.types;
? ? default_type? application/octet-stream;
? ? # 文字編碼
? ? #charset utf-8;
? ? # 設定日志格式 ------------ S ----------------
? ? # 注釋:
? ? #$remote_addr? 與$http_x_forwarded_for 用以記錄客戶端的ip地址晌梨;
? ? #$remote_user? :用來記錄客戶端用戶名稱桥嗤;
? ? #$time_local? : 用來記錄訪問時間與時區(qū);?
? ? #$request? :? 用來記錄請求的url與http協(xié)議仔蝌;
? ? #$status? ? :? 用來記錄請求狀態(tài)泛领;成功是200,
? ? #$body_bytes_s ent? :記錄發(fā)送給客戶端文件主體內(nèi)容大辛簿渊鞋;
? ? #$http_referer? :用來記錄從那個頁面鏈接訪問過來的;
? ? #$http_user_agent? :記錄客戶瀏覽器的相關信息瞧挤;
? ? #log_format? main? '$remote_addr - $remote_user [$time_local] "$request" '
? ? #? ? ? ? ? ? ? ? ? '$status $body_bytes_sent "$http_referer" '
? ? #? ? ? ? ? ? ? ? ? '"$http_user_agent" "$http_x_forwarded_for"';
? ? #access_log? logs/access.log? main;
? ? # 訪問日志格式? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
? ? log_format? access_log_format? '$remote_addr - $remote_user [$time_local] $request '
? ? ? ? '"$status" $body_bytes_sent "$http_referer" '
? ? ? ? '"$http_user_agent" "$http_x_forwarded_for"';
? ? # 訪問日志文件,不要隨意修改日志文件名稱路徑锡宋,日志切割腳本需要同步修改
? ? #access_log? /log/nginx_logs/proxy.access.log? access_log_format;
? ? # 關閉訪問日志
? ? access_log? ? ? ? ? ? ? ? ? off;
? ? # 設定日志格式 ------------ E ----------------
? ? # sendfile 指令指定 nginx 是否調(diào)用 sendfile 函數(shù)(zero copy 方式)來輸出文件,對于普通應用特恬,
? ? # 必須設為 on,如果用來進行下載等應用磁盤IO重負載應用执俩,可設置為 off,以平衡磁盤與網(wǎng)絡I/O處理速度癌刽,降低系統(tǒng)的uptime
? ? sendfile? ? ? ? ? ? ? ? ? ? on;
? ? # 開啟gzip壓縮
? ? gzip? ? ? ? ? ? ? ? ? ? ? ? off;
? ? gzip_min_length? ? ? ? ? ? ? 1k;?
? ? gzip_buffers? ? ? ? ? ? ? ? 4 16k;?
? ? gzip_http_version? ? ? ? ? ? 1.1;?
? ? gzip_comp_level? ? ? ? ? ? ? 2;?
? ? gzip_proxied? ? ? ? ? ? ? ? expired no-cache no-store private auth;
? ? gzip_types? ? ? ? ? ? ? ? ? text/plain application/x-javascript text/css application/xml;?
? ? gzip_vary? ? ? ? ? ? ? ? ? ? on;
? ? gzip_disable? ? ? ? ? ? ? ? 'MSIE [1-6]\.';
? ? server_names_hash_bucket_size 128;
? ? #設定請求緩沖
? ? # 客戶端請求頭部的緩沖區(qū)大小役首,這個可以根據(jù)你的系統(tǒng)分頁大小來設置,
? ? # 一般一個請求頭的大小不會超過1k显拜,不過由于一般系統(tǒng)分頁都要大于1k衡奥,
? ? # 所以這里設置為分頁大小。 分頁大小可以用命令getconf PAGESIZE 取得
? ? # client_header_buffer_size該值必須設置為“系統(tǒng)分頁大小”的整倍數(shù)
? ? client_header_buffer_size? ? 4k;
? ? client_body_buffer_size? ? ? 512k;?
? ? large_client_header_buffers? 4 32k;
? ? client_max_body_size? ? ? ? 8m;
? ? # 連接超時時間
? ? #keepalive_timeout? ? ? ? ? 0;
? ? keepalive_timeout? ? ? ? ? ? 60;
? ? client_header_timeout? ? ? ? 3m;? ?
? ? client_body_timeout? ? ? ? ? 3m;?
? ? send_timeout? ? ? ? ? ? ? ? 3m;?
? ? tcp_nopush? ? ? ? ? ? ? ? ? on;?
? ? tcp_nodelay? ? ? ? ? ? ? ? ? on;?
? ? # 為了安全讼油,關閉版本顯示
? ? server_tokens? ? ? ? ? ? ? ? off;
? ? # 注:proxy_temp_path和proxy_cache_path指定的路徑必須在同一分區(qū)
? ? proxy_temp_path? /data/nginx/proxy_temp_path;
? ? # 設置緩存區(qū)名稱為cache_one杰赛,內(nèi)存緩存空間大小為8192MB,1天沒有被訪問的內(nèi)容自動清除矮台,硬盤緩存空間大小為10GB乏屯。
? ? # 注意這個配置是在server標簽外,levels指定該緩存空間有兩層hash目錄瘦赫,第一層目錄是1個字母辰晕,第二層為2個字母,
? ? # 保存的文件名就 會類似/path/to/cache/c/29/b7f54b2df7773722d382f4809d65029c确虱;
? ? # keys_zone為這個空間起個 名字含友,10m指空間大小為10MB;
? ? # inactive的5m指緩存默認時長5分鐘;max_size的2m是指單個文件超過2m的就不緩 存窘问;
? ? # clean_time指定一分鐘清理一次緩存? ?
? ? proxy_cache_path? /data/nginx/proxy_cache_path levels=1:2 keys_zone=cache_proxy:8192m inactive=5m max_size=10g;
? ? #proxy_cache_path /data/nginx/proxy_cache_path levels=1:2 keys_zone=cache_proxy:10m inactive=10m max_size=1000M;
? ? proxy_connect_timeout? ? ? ? 60;
? ? proxy_send_timeout? ? ? ? ? 60;
? ? proxy_read_timeout? ? ? ? ? 60;
? ? proxy_buffer_size? ? ? ? ? ? 16k;
? ? proxy_buffers? ? ? ? ? ? ? ? 4 64k;?
? ? proxy_busy_buffers_size? ? ? 128k;?
? ? proxy_temp_file_write_size? 128k;
? ? # 路徑規(guī)劃和RangeSpider服務集群
? ? upstream? jxswapi {
? ? ? ? server? 115.231.73.253:80;
? ? }
? ? # HTTP
? ? server
? ? {
? ? ? ? # 監(jiān)聽端口
? ? ? ? listen? 8889;
? ? ? ? # 服務名稱:域名或IP或localhost
? ? ? ? #server_name? gis.sit.shanghaionstar.com;
? ? ? ? server_name? localhost;
? ? ? ? # TPI發(fā)布
? ? ? ? location /jxtpi/ {
? ? ? ? ? ? # 加載代理設定
? ? ? ? ? ? include nginx_proxy.conf;
? ? ? ? ? ? # 代理轉發(fā)? ? ? ?
? ? ? ? ? ? proxy_pass? ? ? ? http://jxswapi/jxtpi;
? ? ? ? ? ? # 超時設定
? ? ? ? ? ? expires 1d;? ? ? ? ? ?
? ? ? ? }
? ? ? ? location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
? ? ? ? {
root /data/tomcat/webapps/jxtpi;
? ? ? ? if (-f $request_filename) {
? ? ? ? ? expires 1d;
? ? ? ? ? break;
? ? ? ? ? }
? ? ? ? }
? ? ? ? ? location ~ .*\.(js|css)$
? ? ? ? {
? ? ? ? root /data/tomcat/webapps/jxtpi;
? ? ? ? if (-f $request_filename) {
? ? ? ? ? expires 1d;
? ? ? ? ? break;
? ? ? ? ? }
? ? ? ? ? }
? ? ? ? #用于清除緩存辆童,假設一個URL為http://192.168.8.42/test.txt,通過訪問http://192.168.8.42/purge/test.txt就可以清除該URL的緩存惠赫。?
? ? ? ? #location ~ /purge(/.*)?
? ? ? ? #{?
? ? ? ? #? ? #設置只允許指定的IP或IP段才可以清除URL緩存把鉴。?
? ? ? ? #? ? allow 127.0.0.1;?
? ? ? ? #? ? allow 172.31.0.0/16;?
? ? ? ? #? ? allow 10.16.33.0/24;?
? ? ? ? #? ? allow 113.52.181.0/24;?
? ? ? ? #? ? deny all;?
? ? ? ? #? ? proxy_cache_purge cache_proxy $host$1$is_args$args;?
? ? ? ? #}?
? ? ? ? # 擴展名以.php、.jsp儿咱、.cgi結尾的動態(tài)應用程序不緩存庭砍。?
? ? ? ? #{? ? ? ? #location ~ .*\.(php|jsp|cgi)?$
? ? ? ? #? ? proxy_set_header Host $host;?
? ? ? ? #? ? proxy_set_header X-Forwarded-For $remote_addr;?
? ? ? ? #? ? proxy_pass http://jxswapi/jxtpi;?
? ? ? ? #}
? ? ? ? #error_page? 404? ? ? ? ? ? ? /404.html;
? ? ? ? # redirect server error pages to the static page /50x.html
? ? ? ? #
? ? ? ? error_page? 500 502 503 504? /50x.html;
? ? ? ? location = /50x.html {
? ? ? ? ? ? root? html;
? ? ? ? }
? ? }
}