I am having quite some trouble with something that should be pretty
straightforward.
I have an app deployed at http://localhost:9090/app/ , and need to
access it via http://subdomain.domain.com .
Thus I configured the following, which works fine:
location / {
proxy_pass http://localhost:9090/app/;
}
However now I need to access in my code the “subdomain.domain.com ”
variable. I thought passing it through an HTTP header:
location / {
proxy_set_header Host $host;
proxy_redirect false;
proxy_pass http://localhost:9090/app/;
}
and I manage to get the header “Host”, but its value is
“localhost:9090”. Also tried with $proxy_host.
How can I get the value “subdomain.domain.com ” in the Host HTTP header?
Thanks,
Francisco
Okay, I found out (after hours of banging my head).
Apparently I was doing something wrong with Host or $host, it was
redirecting to /app, quite misleading.
location / {
proxy_set_header ServerName $server_name;
proxy_pass http://localhost:9090/app/;
}
I ended up using $server_name (somehow I didn’t figure out before this
is what I wanted ), also changing the header name… and it works!
Francisco
Francisco T. wrote:
I am having quite some trouble with something that should be pretty
straightforward.
I have an app deployed at http://localhost:9090/app/ , and need to
access it via http://subdomain.domain.com .
Thus I configured the following, which works fine:
location / {
proxy_pass http://localhost:9090/app/;
}
However now I need to access in my code the “subdomain.domain.com ”
variable. I thought passing it through an HTTP header:
location / {
proxy_set_header Host $host;
proxy_redirect false;
proxy_pass http://localhost:9090/app/;
}
and I manage to get the header “Host”, but its value is
“localhost:9090”. Also tried with $proxy_host.
How can I get the value “subdomain.domain.com ” in the Host HTTP header?
Thanks,
Francisco
frankmt
December 19, 2009, 3:25pm
3
On Wed, Dec 02, 2009 at 08:28:58PM +0100, Francisco T. wrote:
I ended up using $server_name (somehow I didn’t figure out before this
is what I wanted ), also changing the header name… and it works!
There is no “ServerName” header. Probably, you need just
location / {
proxy_pass http://localhost:9090/app/;
}
proxy_pass http://localhost:9090/app/;
Posted via http://www.ruby-forum.com/ .
nginx mailing list
[email protected]
nginx Info Page
–
Igor S.
http://sysoev.ru/en/
frankmt
December 29, 2009, 10:13pm
4
On Tue, Dec 29, 2009 at 4:27 AM, Francisco T. [email protected]
wrote:
to obtain the server name as a header.
Posted via http://www.ruby-forum.com/ .
nginx mailing list
[email protected]
nginx Info Page
$http_host and $server_name variables are available for use and you
can pass whatever you want to backend. Please see documents at
Module ngx_http_proxy_module .
– Merlin
frankmt
December 29, 2009, 1:27pm
5
Igor S. wrote:
There is no “ServerName” header. Probably, you need just
location / {
proxy_pass http://localhost:9090/app/;
}
This is the first thing I tried. Now I updated nginx to 0.7.x and
$server_name trick doesn’t work anymore. It is still unclear to me how
to obtain the server name as a header.
Btw, it doesn’t have to be an “official” HTTP header… anything will do
as long as I can obtain the “subdomain.domain.com ” in my code.
Could you please show me how?
Thanks!
Francisco