I'm working on a Laravel project (an API) and I have a problem with a custom param in the request header.
I need to send a token in the request header, so I just add a param api_token in my request.
When I am on my local configured with apache2, I can in Laravel get my header request param with $request->header('api_token'), but when I tr on my server configured with nginx, I always get null
For me, there is a problem with nginx and header request, what can I do ?
Any ideas ? Maybe it's not from nginx...
That's because by default Nginx does not allow header with an underscore. You can simply update your header parameter to api-token:
$request->header('api-token');
Or you can configure your Nginx configuration to allow header with an underscore. Somewhere between your server block, add underscores_in_headers directive like this:
server {
...
underscores_in_headers on;
...
}
Also don't forget to reload your Nginx configuration. Read more about this underscores_in_headers directive here.
Hope this solve your issue.
Related
I am running a laravel project on nginx server. On a subpage I try to inject some code by SSI like this:
location /path/ {
subs_filter_types text/html;
subs_filter '</head>' '<!--#include virtual="/another/url"--></head>' i;
ssi on;
}
The injected code is not that I would expect at /another/url/. Instead the whole website /path/ is getting injected. I guess that the laravel router is still routing to the given location.
When I open my-server.com/another/url/ I get the content to inject, but when I try to inject the content at /path/, the content of my-server.com/path/ will be injected.
Is the SSI request still having the inital request location? Could it be, that laravel router is it routing wrong then?
I'm trying to add "client_ip" in to a response header, but I can see the IP address is being printed on the kong apigateway logs but cannot forward it to a response header,
Sample log output:
,"method":"GET"},"client_ip":"49.36.22.209","tries":[{"balancer
I was trying following methods to try it out, but still response header is not printed the ip address.
- name: response-transformer
route: routeName
config:
add:
headers:
- X-Real-IP:${{client_ip}}
Can anyone help me to try enable this header on kong apigateway configs ?
Thanks.
You could use the plugin "serverless-functions"
In your case you would use the "post-function" running on service response at "header-phase".
With this plugin and post-function you can write custom logic with lua and modify the response.
With pre-function you could modify the request.
Kong have a PDK you can use globally.
Either if lb or not you would use
kong.client.get_ip() or kong.client.get_forwarded_ip()
Example Code
local client = kong.client
local response = kong.response
local function set_client_ip_header()
local client_ip = client.get_ip() -- or client.get_forwarded_ip()
response.set_header("X-Real-Ip", client_ip)
end
return set_client_ip_header -- return for memoization
I want to implement a custom nginx cache control method from my scripts, by using a custom header: "Do-Cache".
I used in http block of nginx:
map $sent_http_do_cache $nocache {
public 0;
default 1;
}
And in the server block of nginx:
fastcgi_cache_bypass $nocache;
fastcgi_no_cache $nocache;
So, for Do-Cache: public, nginx should cache the response. Otherwise not.
But this configuration is not working. By debuging into logs the values of $sent_http_do_cache and $nocache are the right ones, until they are used in server block of nginx. If using them in the server block (fastcgi_cache_bypass $nocache, or a simple set $a $nocache), the $nocache variable got the "1" value, and $sent_http_do_cache - "-".
Is the any other way of managing the cache of nginx based on custom header in response?
Caching based on the response header cannot be done because it implies that Nginx must proxy the request back to the backend and check its response, defeating the purpose of the proxy cache.
I want to develop a Monitoring-WebApp for different things with AngularJS as Frontend. One of the core-elements is showing an overview of Nexus-Artifacts/Repositories.
When I request the REST-API I'm getting following error back:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://localhost:9090' is therefore not allowed access.
To fix this error, I need to modify the response headers to enable CORS.
It would be great if anyone is familiar with that type of problem and could give me an answer!
The CORS headers are present in the response of the system you are trying to invoke. (Those are checked on the client side [aka browser this case], you can implement a call on your backend to have those calls and there you can ignore those headers, but that could become quite hard to maintain.) To change those you'll need a proxy. So your application will not call the url directly like
fetch("http://localhost:9090/api/sometest")
There are at least two ways: one to add a proxy directly before the sonar server and modify the headers for everyone. I do not really recommend this because of security reasons. :)
The other more maintaneable solution is to go through the local domain of the monitoring web app as follows:
fetch("/proxy/nexus/api/sometest")
To achieve this you need to setup a proxy where your application is running. This could map the different services which you depend on, and modify the headers if necessary.
I do not know which application http server are you going to use, but here are some proxy configuration documentations on the topic:
For Apache HTTPD mod_proxy you could use a configuration similar to this:
ProxyPass "/proxy/nexus/" "http://localhost:9090/"
ProxyPassReverse "/proxy/nexus/" "http://localhost:9090/"
It is maybe necessary to use the cookies as well so you may need to take a look at the following configurations:
ProxyPassReverseCookiePath
ProxyPassReverseCookieDomain
For Nginx location you could employ something as follows
location /proxy/nexus/ {
proxy_pass http://localhost:9090/;
}
For node.js see documentation: https://github.com/nodejitsu/node-http-proxy
module.exports = (req, res, next) => {
proxy.web(req, res, {
target: 'http://localhost:4003/',
buffer: streamify(req.rawBody)
}, next);
};
Is there any way to access HTTP headers in ISAPI_Rewrite module? Didn't find anything about it. I know IIS URL Rewrite allows you to access headers as server variables - {HTTP_HEADER_NAME} - is there something similar here?
Uh, nevermind...
Missed a line in a documentation:
HTTP header value with the syntax %{HTTP:header}.
http://www.helicontech.com/isapi_rewrite/doc/RewriteCond.htm