I have a.b
domain (for example) and want to serve some github pages (username.github.io/project
) in a.b/c
. It means that I also want to keep my browser url to a.b/c
and showing contents of username.github.io/project
.
I have following settings in nginx module
location /c {
proxy_pass http://username.github.io/project;
proxy_redirect http://username.github.io http://a.b;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
}
if I change proxy_set_header Host $http_host
to proxy_set_header Host $proxy_host
or $host
, it just redirect to http://username.github.io/project
which is not I meant to. How can I do?
Best Answer
Simply send the right Host header to your proxy target by removing the
proxy_set_header Host $http_host
line.If
a.b
is configured as a server name in your server block then you don't even needproxy_redirect
directive if you use a trailing slash in your location prefix and in yourproxy_pass
target as explained in the documentation :So, this should do it :