I need to get the URL from the dotnet-core webapi from where the api is called. The api itself is hosted behind a nginx-proxy in a specific location:
nginx config:
server {
server_name my.domain.com;
root /var/www/html/someotherapp;
index index.php;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log info;
location /myapi/ {
proxy_pass http://localhost:8181/;
proxy_buffering off;
proxy_read_timeout 7200;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
location / {
index index.html;
}
listen 443 ssl; # managed by Certbot
}
dotnet api:
in startup.configureservices:
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders =
ForwardedHeaders.All;
});
and startup.configure
app.UseForwardedHeaders();
I can call this app now via
And while trying to get the URL I'm called with in the controller with something like
$"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{HttpContext.Request.Path}{HttpContext.Request.QueryString}";
I won't the the location, where the proxy is forwarding, so the result is always
https://my.domain.com/api/testapi?myquery=test
missing the "myapi" location.
Any Idea how to get the location as well?