Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nginx 경고 대응 - the "listen ... http2" directive is deprecated #110

Closed
1 task done
ibin79 opened this issue Nov 17, 2024 · 2 comments
Closed
1 task done

Nginx 경고 대응 - the "listen ... http2" directive is deprecated #110

ibin79 opened this issue Nov 17, 2024 · 2 comments
Assignees

Comments

@ibin79
Copy link
Contributor

ibin79 commented Nov 17, 2024

Nginx 1.25.1 이후, http2 설정 경고 - the "listen ... http2" directive is deprecated

[root@php79 ~]# nginx -v
nginx version: nginx/1.26.2

[root@php79 ~]# nginx -t
nginx: [warn] the "listen ... http2" directive is deprecated, use the "http2" directive instead in /etc/nginx/conf.d/php79.conf:52

참고) 설정 테스트 (-t) 시 경고(warn)만 있고, nginx 시작은 가능합니다.

1.25.1 이후 해결 방법

이미 추가된 사이트는 nginx 사이트.conf 에서 http2 구문만 수정하면 됩니다.

  • http2 선언된 설정 파일 검색
[root@php79 ~]# grep http2 /etc/nginx/conf.d/*.conf

    listen 443 ssl http2;
  • 다음처럼 listen 에서 http2 삭제후, 다음 라인에 http2 on 추가
    listen 443 ssl; 
    http2 on;

https://nginx.org/en/docs/http/ngx_http_v2_module.html

주의) 1.24 등 이전 버전에서 http2 on 미지원

1.24 버전에서 http2 on 설정을 추가하면 다음처럼 Nginx 가 시작되지 않는 장애가 생깁니다.

[root@php79 ~]# nginx -v
nginx version: nginx/1.24.0

[root@php79 ~]# nginx -t
nginx: [warn] protocol options redefined for 0.0.0.0:443 in /etc/nginx/conf.d/php79.conf:74
nginx: [emerg] unknown directive "http2" in /etc/nginx/conf.d/php79.conf:75
nginx: configuration file /etc/nginx/nginx.conf test failed

[root@php79 ~]# systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

stack 개선

  • stack 1.5.0 에서 기본 템플릿을 nginx 1.25.1 용으로 분기 예정. letsencrypt/template-server.conf

참고) 1.25.1 변경 로그

hanges with nginx 1.25.1                                        13 Jun 2023

    *) Feature: the "http2" directive, which enables HTTP/2 on a per-server
       basis; the "http2" parameter of the "listen" directive is now
       deprecated.

http://nginx.org/en/CHANGES-1.26

@ibin79 ibin79 self-assigned this Nov 17, 2024
@ibin79 ibin79 changed the title nginx: [warn] the "listen ... http2" directive is deprecated Nginx 경고 대응 - the "listen ... http2" directive is deprecated Nov 17, 2024
@ibin79
Copy link
Contributor Author

ibin79 commented Nov 17, 2024

stack 개선

  • 이미 추가된 사이트의 nginx conf 파일은 수정하지 않음. 이슈 본문에서 직접 수정 가이드만 안내.

  • 신규 추가시에만 nginx 버전 확인하여 SSL 인증서 설치시 설정 분기

    • 2개 버전용 설정중 미사용 설정은 주석 처리하여 일단 포함해둠. 추후 버전 변경시 주석 치환만으로 쉽게 변경 가능하도록 함.

Nginx 1.25.1 이상 - letsencrypt/template-server-1.25.1.conf * 신규 추가

    #listen 443 ssl http2;    # nginx 1.25.1 이전 버전 (1.24.0 등)
    listen 443 ssl;    # nginx 1.25.1 이상 버전
    http2 on;    # nginx 1.25.1 이상 버전  https://github.com/php79/stack/issues/110

Nginx 1.25.1 이전 - letsencrypt/template-server.conf

    listen 443 ssl http2;    # nginx 1.25.1 이전 버전 (1.24.0 등)
    #listen 443 ssl;    # nginx 1.25.1 이상 버전
    #http2 on;    # nginx 1.25.1 이상 버전  https://github.com/php79/stack/issues/110

@ibin79
Copy link
Contributor Author

ibin79 commented Nov 23, 2024

Tip) 사이트가 여러개일 경우 일괄 변경

작업전 /etc/nginx/conf.d/ 디렉토리 백업

  • 변경 대상 확인
grep 'http2;' /etc/nginx/conf.d/*.conf
  • 쉘 스크립트로 일괄 변경
FILES=( `grep -l 'http2;' /etc/nginx/conf.d/*.conf` )
for i in "${FILES[@]}"
do
    echo "replace file : ${i}"
    sed -i 's/^    listen 443 ssl http2\;/    listen 443 ssl\;\n    http2 on\;/' "${i}"
done
  • 변경 확인후, nginx 설정 테스트후 재시작
grep 'http2;' /etc/nginx/conf.d/*.conf
nginx -t && systemctl restart nginx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant