需求:通过网址http://www.domain.com可以访问vue项目的首页,通过接口地址http://www.domain.com/api/v1/xxxAction可以访问node上的某个接口服务。
实现:
server {listen 80;server_name www.domain.com;location /api/{proxy_pass http://127.0.0.1:7001;#通过api匹配到接口,转发到内部的node服务上}location / {root /home/lsk/bktt_vue/dist;#通过把域名根目录指向vue包地址实现vue首页的访问index index.html index.htm;#如果没有给出index,默认初始页为index.html或.htmadd_header 'Access-Control-Allow-Origin' '*';#所有接口支持跨域访问}}
