I would like to rewrite an URL to send it to a different vhost.
Here is my first Host:
upstream splunk {
server 127.0.0.1:8000;
}
upstream test{
server 127.0.0.1:88;
}
server {
listen 88;
root /var/www/errors/;
index index.html;
location ~* ^.+\.(jpeg|gif|png|jpg)
{
root /var/www/images/;
}
}
In /var/www/errors/ : 495.html 496.html 404.html
Here is my proxy:
server {
listen 443 ssl spdy default_server;
error_page 404 @404;
error_page 495 @495;
error_page 495 @496;
location @404
{
rewrite ^ /404.html break;
proxy_pass http://test;
}
location @495
{
rewrite ^ /495.html break;
proxy_pass http://test;
}
location @496
{
rewrite ^ /496.html break;
proxy_pass http://test;
}
location /
{
if ($ssl_client_verify = NONE)
{
return 496;
}
if ($ssl_client_verify != SUCCESS) {
return 495;
}
proxy_pass http://splunk;
proxy_set_header X-Remote-User $username;
proxy_set_header X_Remote_User $username;
proxy_set_header X-SSL-Client-Serial $ssl_client_serial;
proxy_set_header X-SSL-Client-Verify $ssl_client_verify;
proxy_set_header X-SSL-Client-S-DN $ssl_client_s_dn;
proxy_set_header X-SSL-Client-S-DN-CN $username;
}
}
The first server is working well and I can access without any problem to index.html, 404.html and so on. The second one should rewrite the URI to send to the appropriate page on the first server. With my current configuration, I keep getting 400 Bad Request.
Thanks a lot in advance
EDIT: With the break
keyword, the pages are redirected properly. Unfortunately, the images in the target pages (404.html for instances) are not loaded and the server sends a 400 Bad Request. This is strange since I am able to see the page properly when I directly connect to this vhost (so the HTML is correct).
EDIT2: Access logs from second vhost:
172.20.175.133 - - [19/Mar/2016:16:09:31 -0700] "GET / HTTP/1.1" 400 728 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"
172.20.175.133 - - [19/Mar/2016:16:09:32 -0700] "GET /logo.jpg HTTP/1.1" 400 728 "https://secondvhost.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"
172.20.175.133 - - [19/Mar/2016:16:09:32 -0700] "GET /images/logo.jpg HTTP/1.1" 400 728 "https://secondvhost.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"
172.20.175.133 - - [19/Mar/2016:16:09:32 -0700] "GET /var/www/images/logo.jpg HTTP/1.1" 400 728 "https://secondvhost.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"
172.20.175.133 - - [19/Mar/2016:16:09:32 -0700] "GET /favicon.ico HTTP/1.1" 400 728 "https://secondvhost.net/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36"
There is no 400 from the first vhost (the landing one).