问题
I have a sails 1.0.2 app, which runs on an Ubuntu 18.04.1 LTS instance. Further, a reverse proxy (Apache) redirects HTTPS (443) requests from the public-side to my specified sails port (4433 in my case).
This works fine when I lift the app using sails lift --port=4433
, the CLI states that the app is listening to port 4433 - when I visit my app from the outside via https(/:443), I can see my app.
According to sails documentation, I set up my production environment in env/production.js
and tried deploying the app by node app.js --prod
. So far, this also works, at least the CLI states, that the app is listening to port 4433 (like before). There is one warning: If your app is behind a proxy or load balancer [...], you may also need to set sails.config.http.trustProxy to true.
. Well, I did that - double and triple checked, the production.js
file has trustProxy uncommented/set to true.
Eventually, when I try accessing the site after the sails app is deployed using --prod
, I get a too many redirects
error in my browser.
So my question is, why is the sails.config.http.trustProxy
flag being ignored in my production.js - or is this not the cause of the problem?
Official sails.js documentation / deployment
回答1:
Found the problem, for future reference: in staging
and production
environments, the sails hooks/custom.js hook forwards GET requests, according to their subdomain. 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
.
By uncommenting this forwarding-rule (-> here), everything works fine now.
So the http.trustProxy
flag didn't have anything to do with the issue at all.
来源:https://stackoverflow.com/questions/52333236/http-trustproxy-flag-not-recognized-when-deploying-sails-app-in-production-mode