ionic server 浏览器无法调用API接口

1. 电脑配置nginx环境

2. nginx 配置指向ionic工程目录下的www目录,进行代理

3. nginx config配置(underscores_in_headers on; token 无法传递的问题)

***.conf文件内容设置

server {
 listen       84;
 server_name  localhost;
 root /Users/sstek_mars/Desktop/pabupa/APP/app-patient/www;
 access_log  /usr/local/etc/nginx/logs/access.log;
 location / {
   try_files $uri @prerender;
 }


 location @prerender {
  set $prerender 0;
  if ($http_user_agent ~* "baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator") {
    set $prerender 1;
  }
  if ($args ~ "_escaped_fragment_") {
    set $prerender 1;
  }
  if ($http_user_agent ~ "Prerender") {
    set $prerender 0;
  }
  if ($prerender = 0) {
    rewrite .* /index.html break;
  }
 }


 location ^~ /build/ {
  root /Users/sstek_mars/Desktop/pabupa/APP/app-patient/www;
 }
 location ^~ /assets/ {
  root /Users/sstek_mars/Desktop/pabupa/APP/app-patient/www;
 }
 location ^~ /core/ {
  root /Users/sstek_mars/Desktop/pabupa/APP/app-patient/www;
 }
 location ^~ /vendor/ {
  root /Users/sstek_mars/Desktop/pabupa/APP/app-patient/www;
  expires 1d;
 }
 location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css|json|xlsx|xls|xlsm)$ {
  root /Users/sstek_mars/Desktop/pabupa/APP/app-patient/www;
  expires 1d;
 }
 location ^~ /api/forum {
  proxy_pass http://192.168.1.200:8080/forum;
 }
 location ^~ /api {
  client_max_body_size    1000m;
  proxy_pass http://192.168.1.***/api;#api的地址
 }


}

猜你喜欢

转载自blog.csdn.net/strong90/article/details/79670138