简体   繁体   English

ERR_TOO_MANY_REDIRECTS 使用自定义 baseUrl 访问我的风帆应用程序时

[英]ERR_TOO_MANY_REDIRECTS when accessing my sails app with custom baseUrl

I am running my app on production mode with baseUrl defined in production.js ( baseUrl: ' http://example.net:1330 ')我正在使用 production.js 中定义的 baseUrl 在生产模式下运行我的应用程序( baseUrl: ' http://example.net:1330 ')

I have made an entry in hosts file to resolve example.net to localhost.我在 hosts 文件中创建了一个条目来将 example.net 解析为 localhost。

My app starts fine on prod mode but when I access with example.net:1330/ it shows ERR_TOO_MANY_REDIRECTS .我的应用程序在 prod 模式下启动正常,但是当我使用 example.net:1330/ 访问时,它显示 ERR_TOO_MANY_REDIRECTS 。 Goes on redirection loop .继续重定向循环。 It runs perfectly when accessed on localhost在本地主机上访问时它运行完美

I have set my Cors我已经设置了我的 Cors

cors: { allRoutes: true, allowOrigins: '*', allowCredentials: false }, cors: { allRoutes: true, allowOrigins: '*', allowCredentials: false },

Any suggestion what am I missing任何建议我错过了什么

Please set baseUrl in production.js excluding port.请在production.js设置baseUrl ,不包括端口。

It means, if you want to serve http://example.net:1330 , please set baseUrl: 'http://example.net' .这意味着,如果您想提供http://example.net:1330服务,请设置baseUrl: 'http://example.net'

Don't set baseUrl: 'http://example.net:1330'不要设置baseUrl: 'http://example.net:1330'

In the custom hook code, they compare req.hostname and url.host to decide whether calling redirection or not.在自定义钩子代码中,他们比较req.hostnameurl.host来决定是否调用重定向。 While req .hostname cannot have port, url.host can have port if you set it with port.虽然req .hostname 不能有端口,但url.host可以有端口,如果你用端口设置它。

Found the problem.发现问题了。 For future reference: in staging and production environments, the sails hooks/custom.js hook forwards GET requests, according to their subdomain.供将来参考:在暂存和生产环境中,sails hooks/custom.js hook 根据其子域转发 GET 请求。

In my case this didn't work, because I didn't have a www.myapp.com domain, but something like myapp.department.university.edu.com.就我而言,这不起作用,因为我没有 www.myapp.com 域,而是类似于 myapp.department.university.edu.com 的域。

Detailed ans : http.trustProxy flag not recognized when deploying sails app in production mode详细回答在生产模式下部署sails应用程序时无法识别http.trustProxy标志

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM