본문 바로가기

리눅스

Nginx 및 Apache 웹 서버에서 HTTP/2를 적용하는 방법

728x90

Nginx 및 Apache 웹 서버에서 HTTP/2를 적용하는 방법

Nginx에서 HTTP/2를 적용하는 방법

테스트 환경

  • 운영체제 버전 확인
$ lsb_release -d
Description:	Ubuntu 22.04 LTS
  • openssl 버전 확인
$ openssl version
OpenSSL 3.0.2 15 Mar 2022 (Library: OpenSSL 3.0.2 15 Mar 2022)
  • Nginx 버전 확인
$ nginx -v
nginx version: nginx/1.24.0

Nginx 설정 파일 수정

vim /etc/nginx/conf.d/default.conf
#default.conf configure
server {
    listen 80 default_server;
    server_name _;
    return 301 https://$host$request_uri;
}

# Settings for a TLS enabled server.
server {
    listen 443 ssl http2;
    server_name _;
    root /usr/share/nginx/html;
    index index.html index.htm;
...
}

HTTP/2 프로토콜 확인

curl -s -I --http2 http://example.com | egrep 'HTTP|Server|server'
$ curl -s -I --http2 http://example.com | egrep 'HTTP|Server|server'    
HTTP/1.1 301 Moved Permanently
Server: nginx/1.24.0
curl -s -I --http2 https://example.com:443 | egrep 'HTTP|Server|server'
$ curl -s -I --http2 https://example.com:443 | egrep 'HTTP|Server|server'
HTTP/2 302 
server: nginx/1.24.0
728x90

Apache에서 HTTP/2를 적용하는 방법

테스트 환경

  • 운영체제 정보 확인
$ cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
  • openssl 정보 확인
$ openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

Apache에서 HTTP/2 적용하기

yum install -y epel-release
yum install -y libnghttp2 libnghttp2-devel

Apache 재컴파일

  • --enable-http2 추가
./configure \
--prefix=/usr/local/apache2 \
--enable-rewrite \
--enable-module=so \
--enable-ssl \
--enable-http2 \
--enable-mods-shared=all \
--enable-nonportable-atomics=yes \
--with-ssl \
--with-mpm=worker \
--with-included-apr
make && make install

모듈 확인

ls -l /usr/local/apache2/modules/mod_http2.so
$ ls -l /usr/local/apache2/modules/mod_http2.so
-rwxr-xr-x 1 root root 1038984  4월 28 14:11 /usr/local/apache2/modules/mod_http2.so

httpd.conf 설정

vim /usr/local/apache2/conf/httpd.conf
LoadModule http2_module modules/mod_http2.so

mod_http2 모듈이 설치되어 있는지 확인

/usr/local/apache2/bin/apachectl -t -D DUMP_MODULES | grep http2
$ /usr/local/apache2/bin/apachectl -t -D DUMP_MODULES | grep http2
 http2_module (shared)

Apache 설정 파일 수정

vim /usr/local/apache2/conf/extra/httpd-ssl.conf
ProtocolsHonorOrder On
Protocols h2 h2c http/1.1

아파치 웹 서버 설정 파일에 HTTP2 지원 여부 확인

cat /usr/local/apache2/conf/extra/httpd-ssl.conf | grep -i "^protocol"
$ cat /usr/local/apache2/conf/extra/httpd-ssl.conf | grep -i "^protocol"
ProtocolsHonorOrder On
Protocols h2 h2c http/1.1

HTTP/2 프로토콜 확인

curl -s -I --http2 http://example.com | egrep 'HTTP|Server|server'
$ curl -s -I --http2 http://example.com | egrep 'HTTP|Server|server' 
HTTP/1.1 101 Switching Protocols
HTTP/2 200 
server: Apache/2.4.29 (Unix) OpenSSL/1.0.2k-fips
curl -s -I --http2 https://example.com | egrep 'HTTP|Server|server'
$ curl -s -I --http2 https://example.com | egrep 'HTTP|Server|server'
HTTP/2 200 
server: Apache/2.4.29 (Unix) OpenSSL/1.0.2k-fips

참고URL

- Apache Module mod_http2 : https://httpd.apache.org/docs/2.4/mod/mod_http2.html

- Module ngx_http_v2_module : http://nginx.org/en/docs/http/ngx_http_v2_module.html

 

728x90