http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#API服务负载
upstream list1 {
ip_hash;
server 10.10.110.120:8080 weight=1 max_fails=2 fail_timeout=10s;
server 10.10.110.119:8080 weight=1 max_fails=2 fail_timeout=10s;
}
#管理后台负载
upstream admin1 {
ip_hash;
server 10.10.110.112:8080 weight=1 max_fails=2 fail_timeout=10s;
server 10.10.110.111:8080 weight=1 max_fails=2 fail_timeout=10s;
}
server {
listen 80;
server_name localhost;
#负载配置
location /open-api/ {
proxy_set_header Host $host;
proxy_set_header X-Forward-For $remote_addr;
proxy_pass http://list1/;#最后一个“/”如果不加,向后转发请求时会将location后边的open-api拼接在请求前边,比如原实际请求为queryPage,向后转发的实际请求为open-api/queryPage
}
location /admin/ {
proxy_set_header Host $host;
proxy_set_header X-Forward-For $remote_addr;
proxy_pass http://admin1/;
}
#静态文件配置
location / {
root html/open/main; # 主应用所在的目录
index index.html;
try_files $uri $uri/ /index.html;
}
location /subapp {
alias html/open/subapp;
try_files $uri $uri/ /index.html;
}
location /emp {
alias /opt/nginx/html/employee; # 主应用所在的目录
index index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
静态文件配置中需注意root和alias的区别