0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

httpdサービスの構成とアプリケーション

Posted at

1. httpdサービスの設定ファイル

通常、httpdサービスのメイン構成ファイルは、httpdルートディレクトリにあるconf / httpd.confファイルです。yumを介してインストールされたhttpdサービスのメイン構成パスは、通常、次のとおりです。

httpd-2.2:/etc/httpd/conf/httpd.conf
httpd-2.4:/etc/httpd/conf/httpd.conf

メイン構成ファイルのフォーマットは、大きく3つの部分に分かれています。

セクション1:グローバル環境
セクション2:「メイン」サーバー構成
セクション3:仮想ホスト

ただし、対応する説明はhttpd-2.4バージョンで削除されましたが、httpd-2.2とほぼ同じです。

メイン構成ファイルに加えて、他の構成ディレクトリパスがあります。通常Include conf.d/.conf、Include conf.modules.d/.conf(httpd-2.4)同様のステートメントがメイン構成ファイルで使用され、対応するディレクトリ内の構成ファイルを呼び出します。パスの形式は相対パスです。 、ルートディレクトリは、メイン構成ファイルのServerrootによって決定されます。

この記事のケースはCentos 7.4 httpd-2.4に基づいています。

2. httpdサービスの基本設定

1.監視対象のIPアドレスとインターフェースを変更する
メイン構成ファイルでは、httpdサービス監視IPアドレスとインターフェースの文形式は次のとおりです。

リッスン[IPアドレス:]ポート番号[プロトコル]

このステートメントの使用には、次の注意点があります。

IPアドレスは省略できます。つまり、0.0.0.0はすべてのIPに一致します。
このコマンドListenを複数回繰り返して、複数のIPアドレスとポートを監視できます。
監視対象のソケットを変更した後、サービスプロセスを再起動して有効にする必要があります。
SSL経由での通信に制限されている場合、プロトコルはhttpsとして定義する必要があります。

ユースケース:
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf Listen 80 Listen 192.168.0.109:8080 [root@localhost ~]# systemctl restart httpd [root@localhost ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 192.168.0.109:8080 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::*

2.長い接続を使用する
長い接続とは、tcpリンクが確立された後、各リソースは取得の完了後に完全には切断されないが、他のリソース要求を待ち続けることを意味します。ただし、同時アクセス数が多いサーバーでは、長い接続を使用すると、後続の要求の一部が不可能になります。通常の応答を取得します。この状況では、長い接続タイムアウト期間を短くし、長い接続要求の数を少なく設定することで、状況を緩和できます。
構成コマンドは次のとおりです。

`keepalive On|off
keepAliveTimeout 15
MaxKeepAliveRequests 100

ユースケース:
`[root@localhost ~]# vim /etc/httpd/conf.d/keepalive.conf
KeepAlive on
KeepAliveTimeout 30
MaxKeepAliveRequests 100
[root@localhost ~]# systemctl restart httpd #重启服务

[c:~]$ telnet 192.168.0.109 80 #在电脑终端用telnet测试连接性
Connecting to 192.168.0.109:80...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
GET /index.html HTTP/1.1
Host:192.168.0.109

HTTP/1.1 200 OK
Date: Tue, 01 May 2018 10:06:06 GMT
Server: Apache/2.4.6 (CentOS)
Last-Modified: Tue, 01 May 2018 10:03:41 GMT
ETag: "d-56b2215c57e7e"
Accept-Ranges: bytes
Content-Length: 13
Content-Type: text/html; charset=UTF-8

hello,world/

GET /index2.html HTTP/1.1
Host:192.168.0.109

HTTP/1.1 200 OK
Date: Tue, 01 May 2018 10:06:39 GMT
Server: Apache/2.4.6 (CentOS)
Last-Modified: Tue, 01 May 2018 10:05:43 GMT
ETag: "15-56b221cfe406e"
Accept-Ranges: bytes
Content-Length: 21
Content-Type: text/html; charset=UTF-8

welcome to my office`

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?