使用代理配置托管角度应用程序 [英] Hosting angular application with proxy configuration

查看:43
本文介绍了使用代理配置托管角度应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular创建一个字典应用程序,该应用程序使用牛津字典API来检索数据.在开发环境中,我使用proxy.conf.json转发请求.这是我的proxy.conf.json文件

I am building a dictionary application using angular which uses oxford dictionary API to retrieve the data . In the development environment I have used proxy.conf.json to forward the requests.This is my proxy.conf.json file

{
"/oxfordapi": {
  "target": "https://od-api.oxforddictionaries.com/api/v1/entries/en/",
  "secure": true,
  "changeOrigin": true,
  "logLevel": "debug",
  "headers": {
    "Accept": "application/json",
    "app_id": "cb35ef20",
    "app_key": "603be016c344650e6d8c1da15330f7af"
  },
  "pathRewrite": {"^/oxfordapi" : ""}
 }
}

当我为生产版本构建应用程序并将其托管在我的nginx服务器上时,当我尝试从服务器获取数据时,它总是会出错.我已经阅读了可以在Nginx服务器配置中使用的proxy_pass,但是我是Nginx服务器的新手,请帮助我解决此问题.如果可能,请提供此问题的完整服务器配置.提前感谢

When I build the application for the production version and host it on my nginx server it always gives error when i try to get data from the server. I have read proxy_pass in nginx server config can be used but I am newbie to nginx server please help me fix this problem. If possible give the full server configuration for this issue .Thanks in advance

推荐答案

尝试以下代码:-

server {

      root /home/ubuntu/test/dist/demo; 
      index index.html; 
      server_name test.vivekm.me; 

      location /oxfordapi {
        proxy_pass https://od-api.oxforddictionaries.com/api/v1/entries/en/;
        proxy_set_header Accept application/json;
        proxy_set_header app_id $http_app_id;
        proxy_set_header app_key $http_app_key;
      }

      location / {
            try_files $uri $uri/ /index.html;
      }
    }

这篇关于使用代理配置托管角度应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆