/ Nginx

#Nginx 使用proxy_pass做反向代理的几条建议

  • 1). proxy_pass中,目标服务器不带path
proxy_pass http://<目标服务器>:<端口>
  • 2). 使用rewrite来重写新路径
   rewrite ^ $request_uri;
   # 自动补充index.html
   rewrite ^/$ /index.html;
   # 补齐真正的路径
   rewrite ^/(.*)$ /newpath/$1 break;
  • 3). 即使路径一致也要用rewrite重写,避免二次转义
  • 4). 使用proxy_intercept_errors捕获错误,避免目标服务器暴露