#錯誤日誌保存位置
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#進程號保存文件
#pid logs/nginx.pid;
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;
#打開發送文件
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 60;
#打開gzip壓縮
#gzip on;
#設定負載均衡的服務器列表
#1-輪詢(默認)
# 每個請求按時間順序逐一分配到不同的後端服務器,如果後端服務器down掉,能自動剔除。
#2-weight
# 指定輪詢機率,weight和訪問比率成正比,用於後端服務器性能不均的情況。
# 參數weigth參數表示權值,權值越高被分配到的機率越大
#3-ip_hash
# 每個請求按訪問ip的hash結果分配,這樣每個訪客固定訪問一個後端服務器,可以
# 解決session的問題。
#4-fair
# 這種模式會根據後端服務的響應時間來分配,響應時間短的後端優先分配
upstream mysvr {
#ip_hash;
server 10.10.12.61:8101;
server 10.10.12.61:8102;
server 10.10.12.61:8103;
server 10.10.12.62:8101;
server 10.10.12.62:8102;
server 10.10.12.62:8103;
}
#第一個虛擬主機
server {
#監聽IP端口
listen 8001;
#主機名
server_name localhost;
#設置字符集
#charset koi8-r;
#本虛擬server的訪問日誌 相當於局部變量
#access_log logs/host.access.log main;
location / {
root html; # 指向nginx 安裝目錄下的html文件夾,看具體配置
index index.html index.htm;
#proxy_pass http://mysvr ; #請求轉向mysvr 定義的服務器列表
}
#中間層轉向mysvr進行負載均衡
location /JWebService {
#root html;
#index index.html index.htm;
proxy_pass http://mysvr ; #請求轉向mysvr 定義的服務器列表
#後端的Web服務器可以通過X-Forwarded-For獲取用戶真實IP
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#client_max_body_size 10m; #允許客戶端請求的最大單文件字節數
#client_body_buffer_size 128k; #緩衝區代理緩衝用戶端請求的最大字節數,
#proxy_connect_timeout 90; #nginx跟後端服務器連接超時時間(代理連接超時)
#proxy_send_timeout 90; #後端服務器數據回傳時間(代理髮送超時)
#proxy_read_timeout 90; #連接成功後,後端服務器響應時間(代理接收超時)
#proxy_buffer_size 4k; #設置代理服務器(nginx)保存用戶頭信息的緩衝區大小
#proxy_buffers 4 32k; #proxy_buffers緩衝區,網頁平均在32k以下的話,這樣設置
#proxy_busy_buffers_size 64k; #高負荷下緩衝大小(proxy_buffers*2)
#proxy_temp_file_write_size 64k; #設定緩存文件夾大小,大於這個值,將從upstream服務器傳
}
#文件訪問直接指向磁盤文件
location /FileService {
##root alias
#location ~ ^/awstats/ {
#root /home/awstats/;
#訪問:http://test.com/awstats/ 實際訪問的是/home/awstats/awstats/
#location ~ ^/awstats/ { #使用alias時目錄名後面一定要加“/”
#alias /home/awstats/;
#訪問:http://test.com/awstats/ 實際訪問的是/home/awstats/
root D:\efuture; ##會指向D:\efuture\FileService
autoindex on; ##會自動顯示資源目錄
index noindex.htm;
}
#訪問/tomcat1 的將重新定向到http://127.0.0.1:8381/
location /tomcat1/ {
proxy_pass http://127.0.0.1:8381/;
index index.html index.htm;
}
#訪問/tomcat2 的將重新定向到http://127.0.0.1:8382/
location /tomcat2/ {
proxy_pass http://127.0.0.1:8382/;
index index.html index.htm;
}
#設定查看Nginx狀態的地址
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
auth_basic_user_file conf/htpasswd;
}
#目錄重定向,訪問/phpadmin/ 的將重新定向到http://_/phpadmin
#location /phpadmin/ {
# alias /opt/www/phpadmin/;
# index index.php;
#}
#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;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# 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;
# }
#}
}