Modify http headers on system level (Linux) [close

2020-05-09 23:55发布

问题:

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 8 years ago.

I want to add http header not just in firefox (using "Modify headers" plugin), but on system level. Since I can't add headers in skype's request, for example, or in IDE's, I need a single point in system to add this header. Is it possible in Linux?

P.S. "Smart" guys who want to close the question: can you put your smart comments?

回答1:

You could redirect all outgoing HTTP requests to a proxy, and have that proxy (e.g. Squid) add the headers.

Redirecting all requests to a 80 port (i.e. the default HTTP port) can be done by system-wide iptables tricks (but this is disgusting).



回答2:

Using a proxy is really the only way to do this on a system wide basis. Linux has no concept of HTTP headers... it's just there to manage the underlying sockets. Each client program, however, will need to use the proxy.

For Squid, use request_header_replace configuration directive:

request_header_replace header_name data


回答3:

i actually just ran into this issue, but there isn't a full simple answer to this question. a lot depends on which headers you want to remove. there are some standard http protocol headers which can't be removed on page renders, but to give you some answers to your general question, you should do the following:

ServerSignature Off

ServerTokens Prod

other headers can be removed in your Apache conf file, virtual host definition or your .htaccess file, assuming you're using Apache and you have mod_headers turned on:

<IfModule mod_headers.c>
Header unset HEADER_NAME
</IfModule>

just to reiterate, a lot depends on which headers you want to remove, so if Header unset doesn't work fully, then some of these headers can't be removed without modifications to your apache source or full knowledge of mod_perl to override standard headers. you can also try to use php, or your code of choice to edit headers, but you may experience some issues with that as well.

i hope this helps, again i just went through this, so i hope to help on some of the challenges and pitfalls, if i can :)