developer's diary

最近はc#のエントリが多いです

apacheのソースを少しだけ弄ってGWS(Google Web Server)にする。

若干痛い行為かもしれない。

やりたいこと。

レスポンスヘッダのサーバ名をGoogleと同じgwsにする。
f:id:mitsugi-bb:20110121203903p:image

httpd-2.2.17のcore.cを修正(httpd-2.2.17/server/core.c)

[root@localhost httpd-2.2.17]# vim server/core.c

2801行目のset_banner関数のAP_SERVER_BASEPRODUCTを書き換える。

/*
 * This routine adds the real server base identity to the banner string,
 * and then locks out changes until the next reconfig.
 */
static void set_banner(apr_pool_t *pconf)
{
    if (ap_server_tokens == SrvTk_PRODUCT_ONLY) {
        ap_add_version_component(pconf, AP_SERVER_BASEPRODUCT);
    }
    else if (ap_server_tokens == SrvTk_MINIMAL) {
        ap_add_version_component(pconf, AP_SERVER_BASEVERSION);
    }
    else if (ap_server_tokens == SrvTk_MINOR) {
        ap_add_version_component(pconf, AP_SERVER_BASEPRODUCT "/" AP_SERVER_MINORREVISION);
    }
    else if (ap_server_tokens == SrvTk_MAJOR) {
        ap_add_version_component(pconf, AP_SERVER_BASEPRODUCT "/" AP_SERVER_MAJORVERSION);
    }
    else {
        ap_add_version_component(pconf, AP_SERVER_BASEVERSION " (" PLATFORM ")");
    }

    /*
     * Lock the server_banner string if we're not displaying
     * the full set of tokens
     */
    if (ap_server_tokens != SrvTk_FULL) {
        banner_locked++;
    }
    server_description = AP_SERVER_BASEVERSION " (" PLATFORM ")";
}

static void set_banner(apr_pool_t *pconf)
{
    if (ap_server_tokens == SrvTk_PRODUCT_ONLY) {
        ap_add_version_component(pconf, "gws");
    }

コンパイル。

[m@localhost httpd-2.2.17]$ ./configure --prefix=/usr/local/gws
[m@localhost httpd-2.2.17]$ make
[m@localhost httpd-2.2.17]$ sudo make install

設定ファイル(/usr/local/gws/conf/httpd.conf)に1行追加

ServerTokens ProductOnly

apache起動

[m@localhost httpd-2.2.17]$ sudo /usr/local/gws/bin/apachectl start

確認

chromeでアクセスして[Shift]+[Ctrl]+[j]を押してヘッダ確認。
f:id:mitsugi-bb:20110121203904p:image

nmapでポートスキャンしたら

PORT   STATE SERVICE VERSION
80/tcp open  http?

となった。

http?