nginx配置

2018-11-26 14:49:55

强烈建议使用nginx托管前端静态资源,并反向代理后端服务,配置如下

server {

  listen 8000;
  server_name localhost;
  set $node_port 7002;

  root /Users/wind/Documents/temp/cabloy-demo/dist;

  location /public {
    root /Users/wind/cabloy/cabloy-demo;
    internal;
  }

  location /api/ {
    proxy_http_version 1.1;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Host $server_name;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header Host $http_host;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_pass http://127.0.0.1:$node_port$request_uri;
    proxy_redirect off;
  }

}
名称 说明
root 前端静态资源
location /public 存储系统运行中产生的资源文件,比如上传的图片文件
location /api/ 后端服务


评论: