> 文档中心 > Nginx反向代理、静态资源下载

Nginx反向代理、静态资源下载


1、反向代理

server {.....# 代理后端服务location /demo {proxy_pass  http://localhost:10008/demo;port_in_redirect   on;proxy_redirect     off;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   Upgrade $http_upgrade;proxy_set_header   Connection "upgrade";}# 代理前端页面location /test {alias /home/web/build/;  #注意后面加上 `/`index index.html;}}

2、静态资源下载

location /resource {    expires 24h;# 强制下载if ($request_filename ~* ^.*?.(txt|doc|pdf|rar|gz|zip|rar|docx|exe|xlsx|xls|ppt|pptx)$){     add_header Content-Disposition attachment; }  add_header Access-Control-Allow-Origin *;  add_header Access-Control-Allow-Headers X-Requested-With;  add_header Access-Control-Allow-Methods GET,POST,PUT,DELETE,OPTIONS; # 资源位置  alias /root/java/testweb/resource; # 是否可以看到文件夹目录  autoindex on;    }