Hi @Kanisius Raychitra Lieka Avisena,
It seems like you're still experiencing problems with the X-Custom header not being delivered to App Service B, and you're looking for an explanation about the need for the extra proxy_set_header commands.
proxy_set_header Host $host;
It sets the original host requested from the client for the Host header in the request forwarded to. It's required when the Host header is the basis for which the backend server (App Service B) can serve content rightly.
proxy_set_header X-Real-IP $remote_addr;
It sends the IP of the client over to the backend server through the X-Real-IP header. It may be used where logging or access controls based on IP are enforced on App Service B.
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
This adds the client's IP address to the X-Forwarded-For header, which keeps track of the IPs the request has passed through. It's widely utilized for recording the original client IP across proxy chains.
Although these headers are helpful for maintaining client data and verifying the backend server processes requests appropriately, they aren't directly impacting the delivery of custom headers such as X-Custom.
As the problem is still ongoing, try the following steps:
Make sure your NGINX configuration on App Service A contains the X-Custom header:
location ^~ /api/ {
proxy_set_header X-Custom "test";
proxy_pass https://apiwebsite.azurewebsites.net/api/;
}
Observe the trailing slashes in the location and proxy_pass directives, which ensure the correct URI structure.
Verify that App Service B is set up to receive and handle the X-Custom header. In PHP, you can get the header with the following code, this code looks for the X-Custom header and prints its value:
$customHeader = $_SERVER['HTTP_X_CUSTOM'] ?? 'Header not received';
echo $customHeader;
Some middlewares or frameworks may remove unknown headers for security purposes. Make sure that whatever middleware is being used in App Service B can forward the X-Custom header.
If you're working with Azure Application Gateway, it's possible to make it rewrite HTTP headers so you can add or replace headers based on your requirements. This will help make sure that the X-Custom header is not removed when forwarding the requests. For more information, refer thishttps://learn.microsoft.com/en-us/azure/application-gateway/rewrite-http-headers-url
Overview:
https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
https://learn.microsoft.com/en-us/azure/frontdoor/front-door-http-headers-protocol
If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.