Haproxy set header and path for a incoming https request - ssl

I have a domain name https://abc.example.com/a/b/c, I have to convert the URL to https://example.com/abc/a/b/c
To achieve it I have done below configuration in the frontend
mode http
http-request set-var(req.rewrite_repo) req.hdr(host),lower,regsub(\.example\.com$,) if { hdr_end(host) -i .example.com }
http-request set-path %[var(req.rewrite_repo)]/v2%[path] if { var(req.rewrite_repo) -m found }
http-request set-header Host example.verizon.com if { var(req.rewrite_repo) -m found }
Now if I give http://abc.example.com it is working fine. But if I give https://abc.example.com it is not working. Could you please help me with it?

Related

How to expose RSK node to an external network?

I am having problems exposing my RSK node to an external IP.
My startup command looks as follows:
java \
-cp $HOME/Downloads/rskj-core-3.0.1-IRIS-all.jar \
-Drsk.conf.file=/root/bitcoind-lnd/rsk/rsk.conf \
-Drpc.providers.web.cors=* \
-Drpc.providers.web.ws.enabled=true \
co.rsk.Start \
--regtest
This is my rsk.conf:
rpc {
providers {
web {
cors: "*",
http {
enabled = true
bind_address = "0.0.0.0"
hosts = ["localhost", "0.0.0.0"]
port: 4444
}
}
}
}
API is accessible from localhost, but from external network I get error 400. How do I expose it to external network?
You should add your external IP to hosts. Adding just 0.0.0.0 is not enough to indicate all IPs to be valid. Port forwarding needs to be enabled for the port number that you have configured in rsk.conf, which in this case is the default value of 4444.
rpc {
providers {
web {
cors: “*”,
http {
enabled = true
bind_address = “0.0.0.0"
hosts = [“localhost”, “0.0.0.0", “216.58.208.100”]
port: 4444
}
}
}
}
where 216.58.208.100 is your external IP

How to setup Varnish to work with Apache and Tomcat

I have a Ubuntu 12.0 server running Varnish 4 on port 80 and the Apache 2.4 in 8080.
I installed Tomcat 7 running on port 8181, which runs only one Liferay site.
I would like to configure Varnish to work with Tomcat also.
How do I set this up?
My current setup is this:
/etc/default/varnish
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,256m"
/etc/varnish/default.vcl
backend default {
.host = "123.456.789.000";
.port = "8080";
.connect_timeout = 580s;
.first_byte_timeout = 580s;
.between_bytes_timeout = 580s;
}
If I point my browser to 123.456.789.000:8181 the Tomcat site works. I will set the registar with my DNS to respond to "www.mytomcatsite.com", but how can I avoid the ":8181" on the URL ?
With Apache everything works fine.
TIA.
From the varnish documentation:
We add a new backend.:
backend java {
.host = "127.0.0.1";
.port = "8000";
}
Now we need tell Varnish where to send the difference URL. Lets look at vcl_recv.:
sub vcl_recv {
if (req.url ~ "^/java/") {
set req.backend_hint = java;
} else {
set req.backend_hint = default;
}
}
If you want this routing to be done on the basis of virtual hosts you just need to inspect req.http.host:
sub vcl_recv {
if (req.http.host ~ "foo.com") {
set req.backend_hint = foo;
} elsif (req.http.host ~ "bar.com") {
set req.backend_hint = bar;
}
}
See:
https://www.varnish-cache.org/docs/trunk/users-guide/vcl-backends.html#multiple-backends
https://www.varnish-cache.org/docs/trunk/users-guide/vcl-backends.html#backends-and-virtual-hosts-in-varnish
Note: This is for Varnish 4. The VCL syntax will be slightly different for Varnish 3.

Why is Varnish redirecting as 301?

I have been deploying a mediawiki docker container (appscontainer/mediawiki) based on Apache2 on a VPS, and I put a fresh install of Varnish on top of it, to be able to proxied different subdomains to the proper applications on the same server.
My current default.vcl configuration file look like the following:
backend default {
.host = "127.0.0.1";
.port = "8080";
}
backend wikimedia {
.host = "localhost";
.port = "8080";
}
sub vcl_recv {
if(req.http.host == "wiki.virtual-assembly.org") {
set req.backend_hint = wikimedia;
}
set req.backend_hint = default;
}
My issue is that when I request the URL http://wiki.virtual-assembly.org, I got redirected via a 301 to the IP adress of the server on port 8080 (port on which the apache2 instance is listening).
Is there a way to tell Varnish to keep the location to be http://wiki.virtual-assembly.org, or is it an apache2 misconfiguration ?
Thanks in advance,
PS: I know my two backends are equivalent, I will change the default in the future when I will have deployed more apps.
Shot in the dark answer. Do you still get a 301 if you put the default backend_req into an else statement instead of outside the if?

Configuring Varnish on cPanel with multiple IP addresses

So I am trying to configure Varnish on my cPanel server which has a primary shared IP along with a few other secondary IP addresses for dedicated domains that are hosted with me.
I have followed the following guide on how to get varnish to run, and it works perfectly for the shared IP domains, but the secondary IP domains won't load at all, going to the default Apache page.
http://crybit.com/how-to-enable-varnish-in-cpanel-server/
I was looking online for other resources and found to configure multiple hosts in the default.vcl file for varnish, so I had done exactly that but the service fails to load as soon as I try launch it, even with just two hosts in the file.
Am I doing something wrong?
backend default {
.host = "11.11.11.11";
.port = "8080";
}
backend secondary1 {
.host = "22.22.22.22";
.port = "8080";
}
I have also tried configuring the following below but also to no success, service won't load!
sub vcl_recv{
if(req.http.host == "www.secondary1.com") || (req.http.host == "secondary1.com) {
set req.backend = secondary1;
} else {
set req.backend = default;
}
}
Hoping that someone can give me a hand!
Can you please check your /etc/sysconfig/varnish file and change your -a flag with your IP's.
-a 192.168.0.1:80,192.168.0.2:80 \

HAProxy not forwarding requests properly

I have this HAProxy config file:
frontend main
bind *:80
use_backend drewgrosscom if { hdr(host) -i drewgross.com }
use_backend drewgrosscom if { hdr(host) -i www.drewgross.com }
backend drewgrosscom
server app1 127.0.0.1:8000 check inter 5000 rise 1 fall 1
But I'm getting "no data received" on both drewgross.com and www.drewgross.com. Accessing www.drewgross.com:8000 and drewgross.com:8000 both work fine though. Any ideas what is going on?
You need to set mode http. This should work:
defaults
mode http
frontend main
bind *:80
use_backend drewgrosscom if { hdr(host) -i drewgross.com }
use_backend drewgrosscom if { hdr(host) -i www.drewgross.com }
backend drewgrosscom
server app1 127.0.0.1:8000 check inter 5000 rise 1 fall 1