nginx.conf配置模板
#user nobody;#指定運行的用戶,Linux最好不要使用root用戶啓動,window環境不需要配置
#error_log logs/error.log;#默認日誌輸入路徑,可以更改
#error_log /dev/null crit;#禁用error_log日誌方法
#error_log logs/error.log notice;#指定輸出日誌級別,可以使用默認級別
#error_log logs/error.log info;
#Linux環境核心轉儲文件大小,win沒有該配置
#worker_rlimit_core 1000m;
#Linux核心轉儲文件位置
# working_directory /usr/local/nginx/logs;
#pid logs/nginx.pid;
#定義環境變量(Linux配置)
#env TESTPATH=/tmp/;
#綁定內核
# worker_processes 4;
# worker_cpu_affinity 1000 0100 0010 0001;
#使用epoll機制,Linux配置
# events {
# use epoll;
# worker_connections 1024;
# }
http {
include mime.types;
default_type application/octet-stream;
#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;
#access_log off;#禁止訪問日誌
#使用啓動高效傳輸文件的模式,直接在磁盤和tcp socket之間傳輸數據,繞開buffer,Linux配置。
sendfile on;
#啓用不等待模式,配合sendfile一起用,Linux配置
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#配置負載均衡
# upstream www.eakom.com {
# ip_hash
# server 10.10.11.150:8888 weight=2;
#轉發失敗3次,30S內不可用
# server 10.10.11.150:8080 weight=5 max_fails=3 fail_timeout=30s;
# server 10.10.12.28:8888 backup; #備用服務器
# }
server {
listen 808;
server_name localhost;
#charset koi8-r;
#啓用Linux上的sendfile系統調用來發送文件,它減少了內核態與用戶態之間的兩次內存複製,
#這樣就會從磁盤中讀取文件後直接在內核態發送到網卡設備,提高了發送文件的效率(小文件)
sendfile on;
#大文件
aio off;
#access_log logs/host.access.log main;
location =/{
#配置負載均衡
#指定反向代理爲上面配置的那個upstream節點“www.eakom.com”
proxy_pass http://www.eakom.com;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_404;
# #鏈接超過一秒馬上鍊接另一個鏈接 ,如果一臺tomcat崩潰,該配置就很重要
proxy_connect_timeout 30;
# 如過加載的是數據量較大的報表,頁面會很慢,參數需要設置大一點(很重要)
proxy_read_timeout 60;
proxy_send_timeout 60;
proxy_buffer_size 256k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_max_temp_file_size 128m;
client_max_body_size 50m;
client_body_buffer_size 256k;
root html;
index index.html index.htm;
}
#指向固定文件夾 D:/software/Project/hh/views
location =/views{
root D:/software/Project/hh;
autoindex on;#張開目錄
}
#指向D:/file/個人/圖片/路徑
location /down/ {
#響應長度超過1M後限速
limit_rate_after 1m;
if ($slow) {
#對請求的限速 默認爲0 不限速
set $limit_rate 4k;
}
limit_rate $limit_rate;
alias D:/file/個人/圖片/;
}
location /upload/ {
#HTTP請求包體的最大值
client_max_body_size 1m;
proxy_pass http://backend;
}
location ~ ^/download/(.*)$ { #正則表達式並傳參
alias D:/file/個人/圖片/$1;#路徑別名
}
location /{
root html;
index index.html index.htm;
}
#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 {
#inernal;#內部訪問
root html;
}
# 靜態資源獲取(~*不區分大小寫 ~爲區分大小寫)
location ~* \.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|ttf)$ {
root D:/software/MyEclipse-2014/Project/tjhy;
}
#錯誤重定向到另外一個location
location / (
error_page 404 @fallback;
)
location @fallback (
proxy_pass http://backend;
)
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}