简体   繁体   English

如何在Rails中隐藏/停止HTTP / 1.1中的服务器版本OK [nginx / 1.0.6 + Phusion Passenger 3.0.9]

[英]How to hide / stop server version in HTTP/1.1 200 OK in rails [ nginx/1.0.6 + Phusion Passenger 3.0.9 ]

Hi in my rails application I am using nginx/1.0.6 , Phusion Passenger to host my rails application. 嗨,在我的rails应用程序中,我正在使用nginx / 1.0.6(Phusion Passenger)托管我的rails应用程序。 But for the security issue I want to stop the display of headers on public network. 但是出于安全问题,我想停止在公共网络上显示标题。 Now when I run the following curl command. 现在,当我运行以下curl命令时。 ` `

curl -I http://domain.name curl-我http://domain.name

it give me the following trace: 它给了我以下跟踪:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Connection: keep-alive
Status: 200
X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.9
ETag: "b7da2b7b2fa6349"
X-UA-Compatible: IE=Edge,chrome=1
X-Runtime: 1.193656
Set-Cookie: demand_session=BAh7ByIQX2NzcmZfdG9rZW4iMUVMREdHRDJGcHhnVzhWNTNsRGhGSWRyNmRQbWZZSnpyZGcwbFYx3D%3D--eb470df0951aac0e6612861ef30ed7a699d073a0; path=/; HttpOnly
Cache-Control: max-age=0, private, must-revalidate
Server: nginx/1.0.6 + Phusion Passenger 3.0.9 (mod_rails/mod_rack)

But I want to hide these headers: Server,Set-Cookie,X-Powered-By,X-UA-Compatible,ETag,Cache-ControlCache-Control to be display. 但是我想隐藏这些标题:Server,Set-Cookie,X-Powered-By,X-UA-Compatible,ETag,Cache-ControlCache-Control待显示。

If you are using proxy you can use and configure directive proxy_hide_header from proxy module by that: 如果您正在使用代理,则可以通过以下方式使用和配置proxy模块中的指令proxy_hide_header

proxy_hide_header X-Powered-By;
proxy_hide_header X-UA-Compatible;
proxy_hide_header X-Runtime;
proxy_hide_header ETag;

# and so on...

But this directive allow you only to hide headers coming from proxy server. 但是此指令仅允许您隐藏来自代理服务器的标头。 For response headers coming from main server not proxy you can use directive set and variable $sent_http_HEADER where HEADER means header name you would like to set. 对于来自主服务器而非代理的响应头,可以使用指令set和变量$sent_http_HEADER ,其中HEADER表示要设置的头名称。 Here an example: 这里是一个例子:

set $sent_http_x_powered_by your_value;
set $sent_http_etag your_value;
set $sent_http_cache_control your_value;

# and so on...

But take in consideration two things: 1. Set directive works only in server , location and if blocks, 2. As you can read in comments to your question it's not realy good idea to hide or change some headers like Cache-Control because they aren't only information but have impact on browser and user clients work. 但是要考虑两点:1. Set指令仅在serverlocationif块中起作用; 2.您可以阅读对问题的注释,因此隐藏或更改某些标头(例如Cache-Control)并不是一个好主意,因为它们不是不仅是信息,而且会影响浏览器和用户客户端的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM