如何在生产中为网站设置代理设置 [英] How to setup proxy settings for a website in production

查看:92
本文介绍了如何在生产中为网站设置代理设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个角度网站,并在proxy.conf.js文件中具有以下代理设置.

I have developed a website in angular and have the following proxy settings in proxy.conf.js file.

const proxyConfig = [
  {
    context: '/web/api/webclients/**',
    target: 'https://10.109.102.109',
    changeOrigin: true,
    secure: false
  },
  {
    context: '/restful/**',
    target: 'https://10.109.110.190',
    changeOrigin: true,
    secure: false
  },
  {
    context: '/api/**',
    target: 'http://10.109.105.107',
    changeOrigin: true,
    secure: false
  }
];

proxy.conf.js在开发模式下可以正常工作.

The proxy.conf.js works as expected when in development mode.

我将它们放在package.json文件中以进行启动和构建.

I have these in the package.json file for start and build.

"build": "ng build --aot --prod",
"start": "ng serve --proxy-config proxy.conf.js -o",

运行"npm run build"并使用生成的文件在IIS 8上托管网站后,需要使用代理设置的页面不起作用.

After I run "npm run build" and use the resulted files to host the website on IIS 8, the pages that need to use the proxy settings do not work.

例如,我的请求 https://localhost/web/api/webclients/authentication 应该转到 https://10.109.102.109/web/api/webclients/authentication

For example, my request https://localhost/web/api/webclients/authentication should go to https://10.109.102.109/web/api/webclients/authentication

如果我在Windows服务器上托管此网站,如何在IIS中设置这些代理设置,或者如果我在非Windows服务器上托管它,如何设置这些代理设置?

How do I setup these proxy settings in IIS if I host this website on Windows server or how to setup these proxy settings if I host it on a non-windows server?

推荐答案

我猜您现在已经找到答案了,但是我还是要尝试回答这个问题,因为这是谷歌搜索时的第一个结果用于角度代理iis".

I'm guessing that you've got the answer by now, but I'm just going to try and answer this anyway because it's the first result when googling for "angular proxy iis".

仅在开发模式下为应用程序提供服务时使用proxy.conf.js文件.为生产而构建时,开发服务器不包含在输出中(因此proxy.conf.js也不包含在输出中).对于生产,您需要再次配置Web服务器(nginx,apache,IIS等)以代理这些路径.

The proxy.conf.js file is only used when serving the application in development mode. When building for production, the development server is not included in the output (and thus proxy.conf.js is also not a part of the output). For production you need to configure your web server again (nginx, apache, IIS etc.) to proxy those paths.

特别是对于IIS,您需要先安装ARR模块,然后才能为后端设置代理规则.看起来此处有关如何正确设置它的详细教程.

For IIS specifically you need the ARR module installed before you can set proxying rules for your backends. Look here for a detailed tutorial of how to properly set it up.

这篇关于如何在生产中为网站设置代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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