117 lines
2.9 KiB
Nginx Configuration File
117 lines
2.9 KiB
Nginx Configuration File
events {
|
|
worker_connections 1024;
|
|
}
|
|
|
|
http {
|
|
include /etc/nginx/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 /var/log/nginx/access.log main;
|
|
error_log /var/log/nginx/error.log;
|
|
|
|
# 基础配置
|
|
sendfile on;
|
|
tcp_nopush on;
|
|
tcp_nodelay on;
|
|
keepalive_timeout 65;
|
|
types_hash_max_size 2048;
|
|
|
|
# Gzip压缩
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_min_length 1024;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_types
|
|
text/plain
|
|
text/css
|
|
text/xml
|
|
text/javascript
|
|
application/json
|
|
application/javascript
|
|
application/xml+rss
|
|
application/atom+xml
|
|
image/svg+xml;
|
|
|
|
# 上游服务器配置
|
|
upstream ruoyi_backend {
|
|
# 轮询负载均衡
|
|
server ruoyi-admin-9900:9900 weight=1 max_fails=3 fail_timeout=30s;
|
|
server ruoyi-admin-9901:9901 weight=1 max_fails=3 fail_timeout=30s;
|
|
server ruoyi-admin-9902:9902 weight=1 max_fails=3 fail_timeout=30s;
|
|
server ruoyi-admin-9903:9903 weight=1 max_fails=3 fail_timeout=30s;
|
|
|
|
# 健康检查
|
|
keepalive 32;
|
|
}
|
|
|
|
# 主服务器配置
|
|
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
|
|
# 静态资源缓存
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
proxy_pass http://ruoyi_backend;
|
|
}
|
|
|
|
# API请求
|
|
location / {
|
|
proxy_pass http://ruoyi_backend;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
|
|
# 超时设置
|
|
proxy_connect_timeout 30s;
|
|
proxy_send_timeout 30s;
|
|
proxy_read_timeout 30s;
|
|
|
|
# 缓冲设置
|
|
proxy_buffering on;
|
|
proxy_buffer_size 4k;
|
|
proxy_buffers 8 4k;
|
|
proxy_busy_buffers_size 8k;
|
|
}
|
|
|
|
# 健康检查端点
|
|
location /health {
|
|
access_log off;
|
|
return 200 "healthy\n";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
|
|
# 状态监控页面
|
|
location /nginx_status {
|
|
stub_status on;
|
|
access_log off;
|
|
allow 127.0.0.1;
|
|
deny all;
|
|
}
|
|
}
|
|
|
|
# 监控和日志配置
|
|
server {
|
|
listen 8080;
|
|
server_name localhost;
|
|
|
|
location / {
|
|
return 200 "Nginx Load Balancer Status\n";
|
|
add_header Content-Type text/plain;
|
|
}
|
|
|
|
location /status {
|
|
stub_status on;
|
|
access_log off;
|
|
}
|
|
}
|
|
}
|