I have a couple of questions - would be happy with any tips advice for either/both of them.
1) Is there any way to set up proxy settings on browsers automatically without having to go into settings and typing the port number etc.? Ideally I would like to run a script that does this automatically.
2) Secondly, I know I can use a PAC file to automatically return the proxy URL and port number. Is there anyway to return the proxy config only if the port is active and listening for a response, and if not return no proxy settings?
For example:
function FindProxyForURL(url, host)
{
if (//proxy server is active and contactable)
return "PROXY 192.168.1.1:8080";
else
return "DIRECT";
}
If you still want to know:
1) http://support.microsoft.com/kb/819961 :D
Related
Short background: If we go back in time to about 2006-ish: We (ie: my company) used a java client app embedded in the browser that connected via port 443 to a C program backend running on port 8068 on an in-house server. At the time when the java app was first developed, port 443 was the only port that we knew would not be blocked by our customers that used the software (ease of installation and possibly the customer in-house staff didn't have the power or knowledge to control their internal firewall).
Fast-forward to 2016, and I'm hired to help develop a NodeJS/Javascript version of that Java app. The Java app continues to be used during development of its replacement, but whoops - we learn that browsers will drop support for embedded Java in the near future. So we switch to Java Web Start, so that the customers can continue to download the app and it still connects to the in house server with it's port 443->8068 routing.
2017 rolls around and don't you know, we can't use the up-coming JS web-app with HTTPS/SSL and the Java app at the same time, 'cause they use the same port. "Ok let's use NGINX to solve the problem." But due to in house politics, customer needs, and a turn-over of web-developer staff, we never get around to truly making that work.
So here we are at 2020, ready to deploy the new web version of the client software, and the whole 443 mess rears it's ugly head again.
Essentially I am looking to allow (for the time being) the Java app to continue using 443, but now need to let the web app use HTTPS too. Back in 2017/2018 we Googled ways to let them cohabitate through NGINX, but we never really got them to work properly, or the examples and tutorials were incomplete or confusing. It seemed like we needed to either use streaming along the lines of https://www.nginx.com/blog/running-non-ssl-protocols-over-ssl-port-nginx-1-15-2/ , or look at the incoming HTTPS header and do an 'if (https) { route to nodeJS server } else { assume it must be the java app and route to port 8068 }' -sort of arrangement inside the NGINX config file.
Past Googled links appear to not exist anymore, so if anyone knows of an NGINX configuration that allows an HTTPS website to hand off to a non-SSL application that still needs to use 443, I would greatly appreciate it. And any docs and/or tutorials that point us in the right direction would be helpful too. Thanks in advance!
You can do this using ssl_preread option. Basically, this option will allow access to the variable $ssl_preread_protocol, that contains the protocol negotiated at SSL port. If no valid protocol was detected, the variable will be empty.
Using this parameters, you could use the follow configuration to your environment:
stream {
upstream java {
server __your_java_server_ip__:8068;
}
upstream nodejs {
server __your_node_js_server_ip__:443;
}
map $ssl_preread_protocol $upstream {
default java;
"TLSv1.2" nodejs;
}
server {
listen 443;
proxy_pass $upstream;
ssl_preread on;
}
}
In your case, this configuration will pass the connection directly to your nodejs and java backend servers, so, nodejs will need to negotiate the SSL. You can pass this work to NGiNX using another server context, like:
stream {
upstream java {
server __your_java_server_ip__:8068;
}
upstream nodejs {
server 127.0.0.1:444;
}
map $ssl_preread_protocol $upstream {
default java;
"TLSv1.2" nodejs;
}
server {
listen 443;
proxy_pass $upstream;
ssl_preread on;
}
}
http {
server {
listen 444 ssl;
__your_ssl_cert_configurations_here__
location / {
proxy_pass http://__your_nodejs_server_ip__:80;
}
}
}
You'll need NGiNX at least version 1.15.2 to this configuration to work, and compiled with ngx_stream_ssl_preread_module module (need to compile with --with-stream_ssl_preread_module configuration parameter, because this module is not built by default).
Source: https://www.nginx.com/blog/running-non-ssl-protocols-over-ssl-port-nginx-1-15-2/
I have a question and my classmate can't fix it either:
how to set up a proxy using requests module?
I think it is easy and I can fix it very quickly. I can use :
proxy = {
'http':'http://74.125.204.103' #just an example
}
and
requests.get(www.youtube.com,proxies = proxy)
And we thought it will connect with 74.125.204.103
But WE ARE WRONG!
It still connects with my own IP address. We use youtube and connect on on video but the times watched is not changing. we also use grabify and IT's still the same.So how can I set up the proxy in other ways?
I believe you're getting this because you only have the proxy specified for HTTP and youtube will redirect you to HTTPS at which point requests has no proxy information.
proxies = {
'http':'http://proxy:port',
'https':'http://proxy:port'
}
Try adding the line for the https schema.
I am trying to write a node program (suggestion for other language are welcome) that can parse and run a corporate proxy script PAC and return the appropriate proxy server to use programmatically.
Are there any existing solutions that can do this? (or is this only possible through a browser)
It seems like PAC files assume certain global functions exist in the execution context such as
shExpMatch()
myIpAddress() // interestingly the nodejs ip package return the true LAN DHCP assigned IP instead of a VPN IP
The goal is to resolve the right proxy server each time a shell is launched (or not set it at all if not behind a proxy)
any tip is greatly appreciate it.
If you're sticking with Node, I'd recommend using something like pac-resolver for this.
const pac = require('pac-resolver');
const fetch = require('node-fetch');
const ip = require('ip');
fetch('http://<proxy_host>:<proxy_port>')
.then(res => res.text())
.then(body => {
// to handle a bug when pinging 8.8.8.8 will time out
// see: https://github.com/TooTallNate/node-pac-resolver/issues/18
findProxy = pac(body, { sandbox: { myIpAddress: ip.address }, });
return findProxy('http://google.com/'));
})
.then(proxy => console.log(proxy))
.catch(err => console.error(err));
In any case, you can look at the repo to see which global functions need to be defined and how that would be done in JavaScript.
If you can use other languages, look at pacparser.
The list of standard global functions, by the way, is here:
dnsDomainIs
shExpMatch
isInNet
myIpAddress
dnsResolve
isPlainHostName
localHostOrDomainIs
isResolvable
dnsDomainLevels
weekdayRange
dateRange
timeRange
alert
I look for a reverse proxy for my NodeJS website. I thought of Varnish or nginx or something else.
What would you suggest me and why (do not necessarily focus on Varnish vs nginx)?
nginx would probably be the best stand-alone solution, however, when I'm working with Node.js, I prefer to keep everything in Node.js so I don't have to worry about the (relatively simple) configuration. I personally use node-reverse-proxy, which allows me to just specify some simple routes in a simple application, and then route it back to the individual applications.
This is the node-reverse-proxy sample code:
var node_reverse_proxy = require('node-reverse-proxy');
var ip = '127.0.0.1';
var reverse_proxy = new node_reverse_proxy({
'first_host.com' : ip + ':8082',
'my.second_host.com' : ip + ':8081',
'my.second_host.com/page/' : ip + ':8080',
'' : ip + ':8080' // catch all other routes
});
reverse_proxy.start(80);
You might find that nginx better suits your needs, but personally, for a simple reverse proxy setup, I do prefer node-reverse-proxy.
On the client I can use window.location.hostname to get the hostname. How can I get the same on the server?
I need this to work behind an Apache proxy, unfortunately Meteor.absoluteUrl() gives me localhost:3000. I also want it to work for different domains, I want one Meteor app that gives different results for different domains.
This question is somewhat related: Get hostname of current request in node.js Express
Meteor.absoluteUrl() given that your ROOT_URL env variable is set correctly.
See the following docs: http://docs.meteor.com/#meteor_absoluteurl.
Meteor doesn't know the outside-facing address of the proxy that it's sitting behind, and the (virtual) domain that this proxy was accessed by would have to be forwarded to the Meteor app for it to do what you are asking for. I don't think this is currently supported.
According to this you can now get the Host header inside Meteor.publish() and Meteor.methods() calls by accessing:
this.connection.httpHeaders.host
Elsewhere in the application, it's probably difficult to determine the Host header that is being used to connect.
If you want the hostname of the server, as configured in /etc/hostname for example:
With meteorite:
$ mrt add npm
In your server code:
os = Npm.require('os')
hostname = os.hostname()
This has no connection to the Host header provided in the incoming request.
updated answer with some of chmac's words from the comment below
In any server-side meteor file you can add:
if (Meteor.isServer) {
Meteor.onConnection(function(result){
var hostname = result.httpHeaders.referer; //This returns http://foo.example.com
});
}
You can fetch host as EnvironmentVariable from DDP object in method and publication. Meteor accounts-base package fetch userId via this way.
const currentDomain = function() {
const currentInvocation = DDP._CurrentMethodInvocation.get() || DDP._CurrentPublicationInvocation.get();
return currentInvocation.connection.httpHeaders.host;
}