Issue
I am using NGINX as a reverse proxy. Below are the setings in nginx.conf file. I want to pass a custom header from the proxy to the back-end HTTP server. I do get the custom header in the HTTP server but I am not getting it in my sockJs connection.
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-RealIPRemote $realip_remote_addr;
proxy_set_header X-RemoteAddr $remote_addr;
proxy_set_header Host $host;
proxy_set_header mycustomhdr customname;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://192.168.1.1:18000;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header mycustomhdr customname;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
In the http server to which the connection is proxied to:
sockServer = sockJs.createServer(
...
sockServer.on('connection', function (conn) {
console.log("conn.headers")
console.log(conn.headers)
Here is what I get:
{ 'x-forwarded-for': '192.168.1.222',
'x-real-ip': '192.168.1.222',
host: 'example.com',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.117 Safari/537.36',
'accept-language': 'en-GB,en-US;q=0.9,en;q=0.8' }
I am not getting the custom header mycustomhdr.
~
Solution
Yeah, you won't. You'll notice several of your other headers are missing too. Not all headers are exposed.
From the docs:
headers (object) Hash containing various headers copied from last receiving request on that connection. Exposed headers include:
origin
,referer
andx-forwarded-for
(and friends). We explicitly do not grant access tocookie
header, as using it may easily lead to security issues (for details read the section "Authorisation").
Answered By - miknik Answer Checked By - Marilyn (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.