Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Tech C**P
Photo
Setup a proxy server by using SwitchyOmega chrome addon. Download and install it from chrome store and setup the credential as picture. Use ssh -D 5300 USERNAME@YOUR_SERVER_IP to proxy your browser traffic (server should be located in Europe or America).

#proxy #switchy_omega #ssh #tunnel #socks
504 Gateway timeout

It is a known issue to many people even those who are not in the programming field. 504 timeout happens when a response for a request has taken longer than expected. There are times that you know and are sure that you need to increase this time. For example if users export a huge excel file as a report. In nginx you can increase this time to what seems to be appropriate from programmer point of view.

In nginx.conf usually in /etc/nginx/ do as follow:

proxy_connect_timeout       600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
send_timeout 600s;

More info: http://nginx.org/en/docs/http/ngx_http_proxy_module.html


#504 #gateway_timeout #timeout #nginx #proxy_read_timeout #proxy_send_timeout
Today I had a problem on nginX. I don't know where to start! :|

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! :D

echo_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: http://sample.com?type=SOMETHING

So far so good. The problem was that when I give call the URL with callback parameter https://api.example.com/geo?callback=test. It
generates /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 http://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 myemail@gmail.com
}


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 myemail@gmail.com
}



#webserver #caddy #proxy #proxy_pass #wss #ws #websocket