httpd.conf line 1 to 7, 24

39
httpd.conf line 1 to 7 , 24 Webサーバ勉強会 #1 #study2study Tue Nov 02, 2010 Naoya Nakazawa (@n0ts) Tuesday, November 2, 2010

Upload: naoya-nakazawa

Post on 31-May-2015

1.216 views

Category:

Technology


1 download

DESCRIPTION

httpd.conf line 1 to 7,24 at #study2study2

TRANSCRIPT

Page 1: httpd.conf line 1 to 7, 24

httpd.confline 1 to 7, 24

Webサーバ勉強会 #1 #study2studyTue Nov 02, 2010

Naoya Nakazawa (@n0ts)

Tuesday, November 2, 2010

Page 2: httpd.conf line 1 to 7, 24

httpdOS

CentOS 5Version

httpd-2.2.3-43.el5Created date at mirror.centos.org

30-Aug-2010 16:57

Tuesday, November 2, 2010

Page 3: httpd.conf line 1 to 7, 24

line 1

Tuesday, November 2, 2010

Page 4: httpd.conf line 1 to 7, 24

ServerTokens OS

Tuesday, November 2, 2010

Page 5: httpd.conf line 1 to 7, 24

ServerTokens - 1HTTPレスポンスのServerヘッダーの設定

よく炎上する設定項目の一つ

僕も昔書いた某ブログで炎上しますた...

Tuesday, November 2, 2010

Page 6: httpd.conf line 1 to 7, 24

ServerTokens - 2Prod[uctOnly] Apache

Major Apache/2

Minor Apache/2.2

Min[imal] Apache/2.2.3

OS Apache/2.2.3 (Unix)

FullApache/2.2.3 (Unix) mod_ssl/2.2.3

OpenSSL/1.0.0a DAV/2 PHP/5.3.2 Phusion_Passenger/3.0.0[Default]

[Conf]

Tuesday, November 2, 2010

Page 7: httpd.conf line 1 to 7, 24

ServerTokens - 3次の設定するとセキュリティ的によいといわれている

ServerTokens ProdServerSignature Offただしブラウザ側でServerヘッダをチェックしていることもあるため隠さない方がよい

Kazuho@Cybozu Labs: サーバシグニチャは隠さないのが当たり前http://labs.cybozu.co.jp/blog/kazuho/archives/2007/09/re_server_sig.php

Tuesday, November 2, 2010

Page 8: httpd.conf line 1 to 7, 24

server/core.cserver/core.c 2791 static const char *set_serv_tokens(cmd_parms *cmd, void *dummy, 2792 const char *arg) 2793 { 2794 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); 2795 2796 if (err != NULL) { 2797 return err; 2798 } 2799 2800 if (!strcasecmp(arg, "OS")) { 2801 ap_server_tokens = SrvTk_OS; 2802 } 2803 else if (!strcasecmp(arg, "Min") || !strcasecmp(arg, "Minimal")) { 2804 ap_server_tokens = SrvTk_MINIMAL; 2805 } 2806 else if (!strcasecmp(arg, "Major")) { 2807 ap_server_tokens = SrvTk_MAJOR; 2808 } 2809 else if (!strcasecmp(arg, "Minor") ) { 2810 ap_server_tokens = SrvTk_MINOR; 2811 } 2812 else if (!strcasecmp(arg, "Prod") || !strcasecmp(arg, "ProductOnly")) { 2813 ap_server_tokens = SrvTk_PRODUCT_ONLY; 2814 } 2815 else { 2816 ap_server_tokens = SrvTk_FULL; 2817 } 2818 2819 return NULL; 2820 }

Tuesday, November 2, 2010

Page 9: httpd.conf line 1 to 7, 24

line 2

Tuesday, November 2, 2010

Page 10: httpd.conf line 1 to 7, 24

ServerRoot “/etc/httpd”

Tuesday, November 2, 2010

Page 11: httpd.conf line 1 to 7, 24

ServerRoot - 1httpdベースディレクトリのパス

この設定があることで、他のディレクティブに相対パスで指定することができる

デフォルト

/usr/local/apache

Tuesday, November 2, 2010

Page 12: httpd.conf line 1 to 7, 24

ServerRoot - 2server/core.c 2386 static const char *set_server_root(cmd_parms *cmd, void *dummy, 2387 const char *arg) 2388 { 2389 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); 2390 2391 if (err != NULL) { 2392 return err; 2393 } 2394 2395 if ((apr_filepath_merge((char**)&ap_server_root, NULL, arg, 2396 APR_FILEPATH_TRUENAME, cmd->pool) != APR_SUCCESS) 2397 || !ap_is_directory(cmd->pool, ap_server_root)) { 2398 return "ServerRoot must be a valid directory"; 2399 } 2400 2401 return NULL; 2402 }

Tuesday, November 2, 2010

Page 13: httpd.conf line 1 to 7, 24

line 3

Tuesday, November 2, 2010

Page 14: httpd.conf line 1 to 7, 24

PidFile run/httpd.pid

Tuesday, November 2, 2010

Page 15: httpd.conf line 1 to 7, 24

PidFile - 1親プロセスIDを記録するファイルを設定する

ServerRoot以下の相対パスでも設定可能

サーバの種類(ServerType)がスタンドアローンのときのみ有効

デフォルト

logs/httpd.pid

Tuesday, November 2, 2010

Page 16: httpd.conf line 1 to 7, 24

PidFile - 2server/mpm_common.c 693 /* standard mpm configuration handling */ 694 #ifdef AP_MPM_WANT_SET_PIDFILE 695 const char *ap_pid_fname = NULL; 696 697 const char *ap_mpm_set_pidfile(cmd_parms *cmd, void *dummy, 698 const char *arg) 699 { 700 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); 701 if (err != NULL) { 702 return err; 703 } 704 705 if (cmd->server->is_virtual) { 706 return "PidFile directive not allowed in <VirtualHost>"; 707 } 708 709 ap_pid_fname = arg ; 710 return NULL; 711 } 712 #endif

Tuesday, November 2, 2010

Page 17: httpd.conf line 1 to 7, 24

line 4

Tuesday, November 2, 2010

Page 18: httpd.conf line 1 to 7, 24

Timeout 120

Tuesday, November 2, 2010

Page 19: httpd.conf line 1 to 7, 24

Timeout - 1Apacheが、次の3つを待つ時間を秒単位で設定する

GET リクエストを受け取るのにかかる総時間

POST や PUTリクエストにおいて、次の TCP パケットが届くまでの待ち時間

レスポンスを返す際、TCP の ACK が返ってくるまでの時間

デフォルト300

Tuesday, November 2, 2010

Page 20: httpd.conf line 1 to 7, 24

line 5

Tuesday, November 2, 2010

Page 21: httpd.conf line 1 to 7, 24

KeepAlive Off

Tuesday, November 2, 2010

Page 22: httpd.conf line 1 to 7, 24

KeepAlive - 1HTTP 1.1の持続的な接続を有効にするかどうかを設定する

HTTP Keep Aliveとは、1回のTCP接続で複数のHTTPリクエストを処理する方式

デフォルト:

On

Tuesday, November 2, 2010

Page 23: httpd.conf line 1 to 7, 24

KeepAlive - 2

運用するサービスごとにオン・オフするか決めるべき項目の1つ

mod_statusのKパラメータに関連する項目

Tuesday, November 2, 2010

Page 24: httpd.conf line 1 to 7, 24

KeepAlive - 3modules/http/http_core.c 57 static const char *set_keep_alive(cmd_parms *cmd, void *dummy, 58 const char *arg) 59 { 60 const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); 61 if (err != NULL) { 62 return err; 63 } 64 65 /* We've changed it to On/Off, but used to use numbers 66 * so we accept anything but "Off" or "0" as "On" 67 */ 68 if (!strcasecmp(arg, "off") || !strcmp(arg, "0")) { 69 cmd->server->keep_alive = 0; 70 } 71 else { 72 cmd->server->keep_alive = 1; 73 } 74 return NULL; 75 } 76

なんと、「o」と設定することも可能!Tuesday, November 2, 2010

Page 25: httpd.conf line 1 to 7, 24

line 6

Tuesday, November 2, 2010

Page 26: httpd.conf line 1 to 7, 24

MaxKeepAliveRequests 100

Tuesday, November 2, 2010

Page 27: httpd.conf line 1 to 7, 24

MaxKeepAliveRequests - 1

Keep Aliveが有効なときに、1回の接続で受付可能なリクエスト回数を設定する

通常は1ページに当たりのファイル数+α

デフォルト

100

Tuesday, November 2, 2010

Page 28: httpd.conf line 1 to 7, 24

MaxKeepAliveRequests - 2

modules/http/http_core.c 77 static const char *set_keep_alive_max(cmd_parms *cmd, void *dummy, 78 const char *arg) 79 { 80 const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); 81 if (err != NULL) { 82 return err; 83 } 84 85 cmd->server->keep_alive_max = atoi(arg); 86 return NULL; 87 }

Tuesday, November 2, 2010

Page 29: httpd.conf line 1 to 7, 24

line 7

Tuesday, November 2, 2010

Page 30: httpd.conf line 1 to 7, 24

KeepAliveTimeout 15

Tuesday, November 2, 2010

Page 31: httpd.conf line 1 to 7, 24

KeepAliveTimeout - 1Keep Aliveが有効なときに、Apacheが次のリクエストを待つ時間を秒単位で設定する

通常はデフォルトより短めに設定する

デフォルト

15

Tuesday, November 2, 2010

Page 32: httpd.conf line 1 to 7, 24

KeepAliveTimeout - 2modules/http/http_core.c 45 static const char *set_keep_alive_timeout(cmd_parms *cmd, void *dummy, 46 const char *arg) 47 { 48 const char *err = ap_check_cmd_context(cmd, NOT_IN_DIR_LOC_FILE|NOT_IN_LIMIT); 49 if (err != NULL) { 50 return err; 51 } 52 53 cmd->server->keep_alive_timeout = apr_time_from_sec(atoi(arg)); 54 return NULL; 55 } 56

Tuesday, November 2, 2010

Page 33: httpd.conf line 1 to 7, 24

line 24

Tuesday, November 2, 2010

Page 34: httpd.conf line 1 to 7, 24

Listen 80

Tuesday, November 2, 2010

Page 35: httpd.conf line 1 to 7, 24

Listen - 1Apacheが待機するポート番号を設定する

Listenディレクティブは、最低1つ以上必須

デフォルトという概念はない

複数書くことで、複数のポートで待機する

Tuesday, November 2, 2010

Page 36: httpd.conf line 1 to 7, 24

Listen - 2形式

Listen [IPアドレス:]ポート番号

設定例

Listen 80Listen 8080Listen 192.168.1.1:80Listen [::]:80

Tuesday, November 2, 2010

Page 37: httpd.conf line 1 to 7, 24

Listen - 3server/listen.c 582 AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy, 583 int argc, char *const argv[]) 584 { 585 char *host, *scope_id, *proto; 586 apr_port_t port; 587 apr_status_t rv; 588 const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY); 589 590 if (err != NULL) { 591 return err; 592 } 593 594 if (argc < 1 || argc > 2) { 595 return "Listen requires 1 or 2 arguments."; 596 } 597 598 rv = apr_parse_addr_port(&host, &scope_id, &port, argv[0], cmd->pool); 599 if (rv != APR_SUCCESS) { 600 return "Invalid address or port"; 601 } 602 603 if (host && !strcmp(host, "*")) { 604 host = NULL; 605 } 606

Tuesday, November 2, 2010

Page 38: httpd.conf line 1 to 7, 24

Listen - 3 Cont. 607 if (scope_id) { 608 /* XXX scope id support is useful with link-local IPv6 addresses */ 609 return "Scope id is not supported"; 610 } 611 612 if (!port) { 613 return "Port must be specified"; 614 } 615 616 if (argc != 2) { 617 proto = "http"; 618 } 619 else { 620 proto = apr_pstrdup(cmd->pool, argv[1]); 621 ap_str_tolower(proto); 622 } 623 624 return alloc_listener(cmd->server->process, host, port, proto); 625 }

重複したListen設定は取り除かれている

Tuesday, November 2, 2010

Page 39: httpd.conf line 1 to 7, 24

Questions?

Tuesday, November 2, 2010