nginx負載均衡、反向代理、文件服務器相關配置。
nginx.conf文件相關配置:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
#後臺服務器組 配置各個負載均衡服務器 (默認輪詢策略)
upstream cskx_group{
server 49.232.143.223:8762;
server 230791mi80.51mypc.cn:25696;
}#反向代理服務
server {
listen 8800;
server_name localhost;location / {
root html;
index index.html index.htm;
}
#支持跨域
location /cskx {
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' '*';
proxy_pass http://cskx_group/cskx;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#配置文件服務器
server {
listen 9000; #端口
server_name localhost; #服務名
charset utf-8; # 避免中文亂碼
root /usr/local/nginx/file; #顯示的根索引目錄,注意這裏要改成你自己的,目錄要存在
location / {
autoindex on; #開啓索引功能
autoindex_exact_size off; # 關閉計算文件確切大小(單位bytes),只顯示大概大小(單位kb、mb、gb)
autoindex_localtime on; # 顯示本機時間而非 GMT 時間
}
}}