背景
最近使用某运营商的云服务器作为正式环境服务器,申请的时候只申请了一个端口,我们的前端页面及后台服务,还有minio,都需要nginx代理这个端口去进行访问。
server {# 监听端口7878listen 7878;server_name localhost;# 前端页面location / {root /home/zx/mima/dist;index index.html index.htm;}# 后端接口地址location /api {proxy_pass http://10.10.40.3:8808;add_header Access-Control-Allow-Origin *;add_header Access-Control-Allow-Methods 'GET,POST,PUT,DELETE,OPTIONS';add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';}# Minio的前端页面location /minio-web/ {proxy_pass http://10.10.10.226:9090/;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";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 5s;proxy_read_timeout 60s;proxy_send_timeout 60s;# 使用sub_filter修改Minio前端页面内部的地址,添加/minio-web前缀sub_filter '="/' '="/minio-web/';sub_filter_once off;# 配置Minio的前端页面代理,静态资源等location ~ ^/minio-web/(.*) {proxy_pass http://10.10.10.226:9090/$1;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";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_read_timeout 86400;proxy_pass_header X-XSRF-TOKEN;proxy_set_header Origin "";}}}
一开始我单独使用上面的配置,minio的页面,包括静态资源文件,及接口都没有问题,但是在预览和下载文件的时候总是报参数是必须的,好像参数没传过去,后来我加上了下面的配置,算是没有问题了
location /minio-web/api/ {proxy_pass http://10.10.10.226:9090/api/;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";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 5s;
}