#nginx進(jìn)程,一般設(shè)置為和cpu核數(shù)一樣
worker_processes 4;
#錯(cuò)誤日志存放目錄
error_log /data1/logs/error.log crit;
#運(yùn)行用戶艾蓝,默認(rèn)即是nginx,可不設(shè)置
user nginx
#進(jìn)程pid存放位置
pid /application/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
#最大文件打開數(shù)(連接)塞祈,可設(shè)置為系統(tǒng)優(yōu)化后的ulimit -HSn的結(jié)果
worker_rlimit_nofile 51200;
cpu親和力配置门粪,讓不同的進(jìn)程使用不同的cpu
worker_cpu_affinity 0001 0010 0100 1000 0001 00100100 1000;
#工作模式及連接數(shù)上限
events
{
use epoll; #epoll是多路復(fù)用IO(I/O Multiplexing)中的一種方式,但是僅用于linux2.6以上內(nèi)核,可以大大提高nginx的性能
worker_connections 1024; #;單個(gè)后臺worker process進(jìn)程的最大并發(fā)鏈接數(shù)
}
###################################################
http
{
include mime.types; #文件擴(kuò)展名與類型映射表
default_type application/octet-stream; #默認(rèn)文件類型
#limit模塊昌阿,可防范一定量的DDOS攻擊
#用來存儲session會話的狀態(tài)锭吨,如下是為session分配一個(gè)名為one的10M的內(nèi)存存儲區(qū)遣疯,限制了每秒只接受一個(gè)ip的一次請求 1r/s
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
limit_conn_zone $binary_remote_addr zone=addr:10m;
include mime.types;
default_type application/octet-stream;
#第三方模塊lua防火墻
lua_need_request_body on;
#lua_shared_dict limit 50m;
lua_package_path "/application/nginx/conf/waf/?.lua";
init_by_lua_file "/application/nginx/conf/waf/init.lua";
access_by_lua_file "/application/nginx/conf/waf/access.lua";
#設(shè)定請求緩存
server_names_hash_bucket_size 128;
client_header_buffer_size 512k;
large_client_header_buffers 4 512k;
client_max_body_size 100m;
#隱藏響應(yīng)header和錯(cuò)誤通知中的版本號
server_tokens off;
#開啟高效傳輸模式
sendfile on;
-------------------------------------------------------------------------------------------------
#激活tcp_nopush參數(shù)可以允許把httpresponse header和文件的開始放在一個(gè)文件里發(fā)布洒宝,
積極的作用是減少網(wǎng)絡(luò)報(bào)文段的數(shù)量
tcp_nopush on;
#激活tcp_nodelay,內(nèi)核會等待將更多的字節(jié)組成一個(gè)數(shù)據(jù)包芯侥,從而提高I/O性能
tcp_nodelay on;
tcp_nopush
View Code
tcp_nodelay
View Code
-------------------------------------------------------------------------------------
#FastCGI相關(guān)參數(shù):為了改善網(wǎng)站性能:減少資源占用泊交,提高訪問速度
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 128k;
----------------------------------------------
#連接超時(shí)時(shí)間,單位是秒
keepalive_timeout 60;
#開啟gzip壓縮功能
gzip on柱查;
#設(shè)置允許壓縮的頁面最小字節(jié)數(shù)廓俭,頁面字節(jié)數(shù)從header頭的Content-Length中獲取。默認(rèn)值是0唉工,表示不管頁面多大都進(jìn)行壓縮研乒。建議設(shè)置成大于1K。如果小于1K可能會越壓越大淋硝。
gzip_min_length 1k;
#壓縮緩沖區(qū)大小雹熬。表示申請4個(gè)單位為16K的內(nèi)存作為壓縮結(jié)果流緩存,默認(rèn)值是申請與原始數(shù)據(jù)大小相同的內(nèi)存空間來存儲gzip壓縮結(jié)果谣膳。
gzip_buffers 4 16k;
#壓縮版本(默認(rèn)1.1竿报,前端為squid2.5時(shí)使用1.0)用于設(shè)置識別HTTP協(xié)議版本,默認(rèn)是1.1继谚,目前大部分瀏覽器已經(jīng)支持GZIP解壓烈菌,使用默認(rèn)即可。
gzip_http_version 1.0;
#壓縮比率花履。用來指定GZIP壓縮比芽世,1壓縮比最小,處理速度最快臭挽;9壓縮比最大捂襟,傳輸速度快,但處理最慢欢峰,也比較消耗cpu資源。
gzip_comp_level 9;
#用來指定壓縮的類型涨共,“text/html”類型總是會被壓縮
gzip_types text/plain application/x-javascript text/css application/xml;
#vary header支持纽帖。該選項(xiàng)可以讓前端的緩存服務(wù)器緩存經(jīng)過GZIP壓縮的頁面,例如用
Squid緩存經(jīng)過Nginx壓縮的數(shù)據(jù)举反。
gzip_vary off;
#開啟ssi支持懊直,默認(rèn)是off
ssi on;
ssi_silent_errors on;
#設(shè)置日志模式
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
#反向代理負(fù)載均衡設(shè)定部分
#upstream表示負(fù)載服務(wù)器池,定義名字為backend_server的服務(wù)器池
upstream backend_server {
server 10.254.244.20:81 weight=1 max_fails=2 fail_timeout=30s;
server 10.254.242.40:81 weight=1 max_fails=2 fail_timeout=30s;
server 10.254.245.19:81 weight=1 max_fails=2 fail_timeout=30s;
server 10.254.243.39:81 weight=1 max_fails=2 fail_timeout=30s;
#設(shè)置由 fail_timeout 定義的時(shí)間段內(nèi)連接該主機(jī)的失敗次數(shù)火鼻,以此來斷定 fail_timeout 定義的時(shí)間段內(nèi)該主機(jī)是否可用室囊。默認(rèn)情況下這個(gè)數(shù)值設(shè)置為 1雕崩。零值的話禁用這個(gè)數(shù)量的嘗試。
設(shè)置在指定時(shí)間內(nèi)連接到主機(jī)的失敗次數(shù)融撞,超過該次數(shù)該主機(jī)被認(rèn)為不可用盼铁。
#這里是在30s內(nèi)嘗試2次失敗即認(rèn)為主機(jī)不可用!
}
###################
#基于域名的虛擬主機(jī)
server
{
#監(jiān)聽端口
listen 80;
server_name www.abc.com abc.com;
index index.html index.htm index.php; #首頁排序
root /data0/abc; #站點(diǎn)根目錄尝偎,即網(wǎng)站程序存放目錄
error_page 500 502 404 /templates/kumi/phpcms/404.html; #錯(cuò)誤頁面
#偽靜態(tài) 將www.abc.com/list....html的文件轉(zhuǎn)發(fā)到index.php饶火。。致扯。
#rewrite ^/list-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)\.html$ /index.php?m=content&c=index&a=lists&catid=$1&types=$2&country=$3&language=$4&age=$5&startDate=$6&typeLetter=$7&type=$8&page=$9 last;
#location 標(biāo)簽肤寝,根目錄下的.svn目錄禁止訪問
location ~ /.svn/ {
deny all;
}
location ~ \.php$
{ #符合php擴(kuò)展名的請求調(diào)度到fcgi server
fastcgi_pass 127.0.0.1:9000; #拋給本機(jī)的9000端口
fastcgi_index index.php; #設(shè)定動(dòng)態(tài)首頁
include fcgi.conf;
}
allow 219.237.222.30 ; #允許訪問的ip
allow 219.237.222.31 ;
allow 219.237.222.32 ;
allow 219.237.222.33 ;
allow 219.237.222.34 ;
allow 219.237.222.35 ;
allow 219.237.222.61 ;
allow 219.237.222.28 ;
deny all; #禁止其他ip訪問
}
location ~ ^/admin.php
{
location ~ \.php$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
allow 219.237.222.30 ;
allow 219.237.222.31 ;
allow 219.237.222.32 ;
allow 219.237.222.33 ;
allow 219.237.222.34 ;
allow 219.237.222.35 ;
allow 219.237.222.61;
allow 219.237.222.28;
deny all;
}
#將符合js,css文件的等設(shè)定expries緩存參數(shù),要求瀏覽器緩存抖僵。
location~ .*\.(js|css)?$ {
expires 30d; #客戶端緩存上述js,css數(shù)據(jù)30天
}
##add by 20140321#######nginx防sql注入##########
###start####
if ( $query_string ~* ".*[\;'\<\>].*" ){
return 444;
}
if ($query_string ~* ".*(insert|select|delete|update|count|\*|%|master|truncate|declare|\'|\;|and|or||||exec).* ")
{
return 444;
}
if ($request_uri ~* "(cost)|(concat\()") {
return 444;
}
if ($request_uri ~* "[+|(%20)]union[+|(%20)]") {
return 444;
}
if ($request_uri ~* "[+|(%20)]and[+|(%20)]") {
return 444;
}
if ($request_uri ~* "[+|(%20)]select[+|(%20)]") {
return 444;
}
set $block_file_injections 0;
if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") {
set $block_file_injections 1;
}
if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") {
set $block_file_injections 1;
}
if ($block_file_injections = 1) {
return 448;
}
set $block_common_exploits 0;
if ($query_string ~ "(<|%3C).*script.*(>|%3E)") {
set $block_common_exploits 1;
}
if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") {
set $block_common_exploits 1;
}
if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") {
set $block_common_exploits 1;
}
if ($query_string ~ "proc/self/environ") {
set $block_common_exploits 1;
}
if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") {
set $block_common_exploits 1;
}
if ($query_string ~ "base64_(en|de)code\(.*)|(concat\()") { return 444; } if ($request_uri ~* "[+|(%20)]union[+|(%20)]") { return 444; } if ($request_uri ~* "[+|(%20)]and[+|(%20)]") { return 444; } if ($request_uri ~* "[+|(%20)]select[+|(%20)]") { return 444; } set $block_file_injections 0; if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") { set $block_file_injections 1; } if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") { set $block_file_injections 1; } if ($block_file_injections = 1) { return 448; } set $block_common_exploits 0; if ($query_string ~ "(<|%3C).*script.*(>|%3E)") { set $block_common_exploits 1; } if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") { set $block_common_exploits 1; } if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") { set $block_common_exploits 1; } if ($query_string ~ "proc/self/environ") { set $block_common_exploits 1; } if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") { set $block_common_exploits 1; } if ($query_string ~ "base64_(en|de)code\(.*") {
set $block_common_exploits 1;
}
if ($block_common_exploits = 1) {
return 444;
}
set $block_spam 0;
if ($query_string ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") {
set $block_spam 1;
}
if ($query_string ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b") {
set $block_spam 1;
}
if ($block_spam = 1) {
return 444;
}
set $block_user_agents 0;
if ($http_user_agent ~ "Wget") {
set $block_user_agents 1;
}
# Disable Akeeba Remote Control 2.5 and earlier
if ($http_user_agent ~ "Indy Library") {
set $block_user_agents 1;
}
# Common bandwidth hoggers and hacking tools.
if ($http_user_agent ~ "libwww-perl") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GetRight") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GetWeb!") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Go!Zilla") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Download Demon") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "Go-Ahead-Got-It") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "TurnitinBot") {
set $block_user_agents 1;
}
if ($http_user_agent ~ "GrabNet") {
set $block_user_agents 1;
}
if ($block_user_agents = 1) {
return 444;
}
###end####
location ~ ^/list {
#如果后端的服務(wù)器返回502鲤看、504、執(zhí)行超時(shí)等錯(cuò)誤耍群,自動(dòng)將請求轉(zhuǎn)發(fā)到upstream負(fù)載均衡池中的另一臺服務(wù)器义桂,實(shí)現(xiàn)故障轉(zhuǎn)移。
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_cache cache_one;
#對不同的HTTP狀態(tài)碼設(shè)置不同的緩存時(shí)間
proxy_cache_valid 200 301 302 304 1d;
#proxy_cache_valid any 1d;
#以域名世吨、URI澡刹、參數(shù)組合成Web緩存的Key值,Nginx根據(jù)Key值哈希耘婚,存儲緩存內(nèi)容到二級緩存目錄內(nèi)
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
#proxy_ignore_headers Set-Cookie;
#proxy_hide_header Set-Cookie;
proxy_pass http://backend_server;
add_header Nginx-Cache "$upstream_cache_status from km";
expires 1d;
}
access_log /data1/logs/abc.com.log access; #nginx訪問日志
}
-----------------------ssl(https)相關(guān)------------------------------------
server {
listen 13820; #監(jiān)聽端口
server_name localhost;
charset utf-8; #gbk,utf-8,gb2312,gb18030 可以實(shí)現(xiàn)多種編碼識別
ssl on; #開啟ssl
ssl_certificate /xs/app/nginx/conf/mgmtxiangqiankeys/server.crt; #服務(wù)的證書
ssl_certificate_key /xs/app/nginx/conf/mgmtxiangqiankeys/server.key; #服務(wù)端key
ssl_client_certificate /xs/app/nginx/conf/mgmtxiangqiankeys/ca.crt; #客戶端證書
ssl_session_timeout 5m; #session超時(shí)時(shí)間
ssl_verify_client on; # 開戶客戶端證書驗(yàn)證
ssl_protocols SSLv2 SSLv3 TLSv1; #允許SSL協(xié)議
ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; #加密算法
ssl_prefer_server_ciphers on; #啟動(dòng)加密算法
access_log /xs/logs/nginx/dataadmin.xiangshang360.com.ssl.access.log access ; #日志格式及日志存放路徑
error_log /xs/logs/nginx/dataadmin.xiangshang360.com.ssl.error.log; #錯(cuò)誤日志存放路徑
}
-------------------------------------------------------------------------
}
nginx配置文件nginx.conf詳解
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門嗅榕,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人吵聪,你說我怎么就攤上這事凌那。” “怎么了吟逝?”我有些...
- 文/不壞的土叔 我叫張陵帽蝶,是天一觀的道長。 經(jīng)常有香客問我块攒,道長励稳,這世上最難降的妖魔是什么佃乘? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮驹尼,結(jié)果婚禮上趣避,老公的妹妹穿的比我還像新娘。我一直安慰自己扶欣,他們只是感情好鹅巍,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著料祠,像睡著了一般骆捧。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上髓绽,一...
- 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼启盛!你這毒婦竟也來了蹦掐?” 一聲冷哼從身側(cè)響起,我...
- 序言:老撾萬榮一對情侶失蹤僵闯,失蹤者是張志新(化名)和其女友劉穎卧抗,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體鳖粟,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡社裆,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了向图。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片泳秀。...
- 正文 年R本政府宣布,位于F島的核電站趴梢,受9級特大地震影響漠畜,放射性物質(zhì)發(fā)生泄漏币他。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一憔狞、第九天 我趴在偏房一處隱蔽的房頂上張望蝴悉。 院中可真熱鬧,春花似錦瘾敢、人聲如沸拍冠。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽庆杜。三九已至,卻和暖如春碟摆,著一層夾襖步出監(jiān)牢的瞬間晃财,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓愉舔,卻偏偏與公主長得像钢猛,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子轩缤,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 定義Nginx運(yùn)行的用戶和用戶組user www www; nginx進(jìn)程數(shù)命迈,建議設(shè)置為等于CPU總核心數(shù)。 wo...
- #定義Nginx運(yùn)行的用戶和用戶組user www www;#nginx進(jìn)程數(shù)典奉,建議設(shè)置為等于CPU總核心數(shù)躺翻。wo...
- 前言 Nginx ("engine x") 是一個(gè)高性能的HTTP和反向代理服務(wù)器,我對Nginx使用有兩三年了卫玖,...
- 逼迫自己迅速讀完這本閑散的散文書假瞬∩驴浚《因上努力,果上隨緣》 開始很慢脱茉,后來就成了秒翻剪芥。 為什么會這樣,很隨緣的散文書...