Today I had a problem on nginX. I don't know where to start! :|
Fair enough, this is my nginx stanza:
 
 
 
 
 
 
So far so good. The problem was that when I give call the URL with callback parameter
generates
Don't ask me! I don't know what are
The output is like the below response for a URL similar to
 
#nginx #stanza #proxy_pass #echo_before_body #echo_after_body
  Fair enough, this is my nginx stanza:
location /geo {
         add_header 'Access-Control-Allow-Origin' '*';
         if ( $arg_callback ) {
             echo_before_body '$arg_callback(';
             echo_after_body ');';
         }
         proxy_pass https://api.example.com/geo;
         proxy_http_version 1.1;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection 'upgrade';
     }NOTE: each part of nginX block is called stanza. I bet you didn't know about this one! :Decho_before_body command will prepend something to the response which will be returned from nginX.echo_after_body will append something to the response.proxy_pass will proxy your requests to a backend server.$arg_callback will get value of parameter callback in URL. So for example if you use $arg_type, you will get the value of        type argument which is provided in URL: https://sample.com?type=SOMETHINGSo far so good. The problem was that when I give call the URL with callback parameter
https://api.example.com/geo?callback=test. Itgenerates
/geo/geo URL instead of /geo. To circumvent the issue I used $request_uri in proxy_pass section proxy_pass https://   api.fax.plus$request_uri;. The route should be OK now, but there is one big problem here now that responses are returned in binary    format instead of JSON. I removed Upgrade & Connection & proxy_http_version lines and it worked like a charm!Don't ask me! I don't know what are
Upgrade and Connection headers.The output is like the below response for a URL similar to
https://api.example.com/geo?callback=test:test(
{
"username": "alireza",
"password": "123456"
}
)
#nginx #stanza #proxy_pass #echo_before_body #echo_after_body
Caddy is the HTTP/2 web server with automatic HTTPS. I wanted to proxy pass websocket service using Caddy but it didn't work:wss.example.org {
    proxy / myservice:8083 {
        header_upstream Host {host}
        header_upstream X-Real-IP {remote}
    }
    tls [email protected]
}
In the documentation it is mentioned that
proxy can proxy pass web sockets too. The problem was about not using websocket inside of the proxy stanza, so we solved it using:wss.example.org {
    proxy / myservice:8083 { 
        header_upstream Host {host}
        header_upstream X-Real-IP {remote}
        websocket
    }
    tls [email protected]
}#webserver #caddy #proxy #proxy_pass #wss #ws #websocket
