실행 시 “[emerg] no events section in configuration

events {} 를 추가하면 된다. 설정 해본적이 없어서 존재하는지 몰랐다. events {} http { server { # Your code here } } 참고 자료 https://stackoverflow.com/questions/54481423/nginx-startup-prompt-emerg-no-events-section-in-configuration

2024-09-15 · 1 min · 25 words

WebSocket 설정

http { map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream websocket { server 192.168.100.10:8010; } server { listen 8020; location / { proxy_pass http://websocket; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $host; } } } 참고 자료 https://www.nginx.com/blog/websocket-nginx/

2024-09-15 · 1 min · 43 words

WAS에서 IP 차단 체크할 때, 웹 서버 IP 확인하는 문제 해결

HTTP 요청을 보낸 사람의 IP를 확인해서 DB에 등록되어 있는 사용자만 허가되도록 구현했다. 하지만 WAS가 HTTP를 받았을 때 항상 IP가 웹 서버(NGINX)의 IP로 인식되는 문제가 있었다. 문제 해결 WAS는 중간에 있는 리버스 프록시의 IP를 인식하는 문제가 있었다. 보통 요청을 보낸 Client의 IP 를 확인하기 위해서 X-Forwarded-For 헤더를 사용한다고 한다. 이를 구현하기 위해서는 크게 2가지 작업이 필요했다. 리버스 프록시 서버인 NGINX 설정 변경 WAS에서 X-Forwarded-For 헤더를 확인하도록 수정 NGINX 설정 변경 nginx에서는 $proxy_add_x_forwarded_for 라는 변수를 제공한다....

2024-09-15 · 1 min · 163 words

Nginx에 USR1 signal을 받으면 발생하는 일

배경 배포 스크립트를 읽어보는 중 kill -USR1 `cat {nginx pid 파일 경로}` 라는 내용이 있었다. 해당 명령의 의미를 이해해본다. signal 종류 kill 명령어를 통해서 특정 프로세스에 signal을 보낼 수 있다. 그 중 SIGUSR1, SIGUSR2는 커스터마이징이 가능한 signal이다. 참고: https://man7.org/linux/man-pages/man7/signal.7.html pid 파일 nginx는 자신의 pid(프로세스 id)를 파일 형태로 저장해둔다. http://nginx.org/en/docs/ngx_core_module.html#pid 따라서 위 명령어는 nginx 프로세스에 SIGUSR1 signal을 보내는 것이다. Nginx가 SIGUSR1 signal을 받은 경우 Nginx에서는 각 signal에 따른 동작이 미리 정의되어 있다....

2024-09-15 · 1 min · 134 words

NGINX 파일 업로드 용량 제한 설정

HTTP multipart를 이용한 파일 업로드 API를 구현했는데 NGINX에서 거부를 하는 문제가 발생했다. 기본적으로 NGINX의 최대 HTTP body 크기는 1MB다. http { ... client_max_body_size 100M; } 또는 server { ... client_max_body_size 100M; } 와 같은 방법으로 파일 용량 제한을 수정할 수 있다. 참고 자료 https://www.tecmint.com/limit-file-upload-size-in-nginx/ https://stackoverflow.com/questions/26717013/how-to-edit-nginx-conf-to-increase-file-size-upload

2024-09-15 · 1 min · 45 words

Nginx 시작하기

Nginx 설치 소스 다운로드 wget http://nginx.org/download/nginx-1.12.2.tar.gz tar xvzf nginx-1.12.2.tar.gz 빌드 cd nginx-1.12.2 ./configure --prefix=/home/{user}/apps/nginx-1.12.2 --user={user} --group={user} --error-log-path=/home/{user}/logs/nginx/error.log --http-log-path=/home/{user}/logs/nginx/access.log --without-http_rewrite_module --without-http_scgi_module --without-http_uwsgi_module --without-http_fastcgi_module make make install 옵션 설명 OS 사용자 -user : OS 사용자 계정. irteam을 권장한다. -group=irteam : OS 사용자의 그룹. irteam을 권장한다. 파일 경로 -prefix : Nginx 빌드 결과물이 들어갈 디렉토리 -error-log-path: 에러 로그를 저장할 경로 -http-log-path : 액세스 로그를 저장할 경로 모듈 선언 -without-http_scgi_module : http_scgi_module 모듈 제외 -without-http_uwsgi_module : http_uwsgi 모듈 제외 -without-http_fastcgi_module : fastcgi_module 모듈 제외 -without-http_rewrite_module : http_rewrite_module 제외 -with-http_ssl_module : HTTPS로 서비스하기 위한 모듈 추가 -with-http_v2_module : HTTP/2로 서비스하기 위한 모듈 추가 그 외 다양한 옵션...

2024-09-15 · 4 min · 708 words

NGINX docker container 생성하기

크게 2가지 파일을 만들어줘야된다. 1. Dockefile FROM nginx COPY nginx.conf /etc/nginx/nginx.conf COPY fullchain.pem /etc/letsencrypt/live/hy-notice.kro.kr/fullchain.pem COPY privkey.pem /etc/letsencrypt/live/hy-notice.kro.kr/privkey.pem nginx.conf: nginx의 설정을 저장해두는 파일이다. fullchain.pem, privkey.pem: TLS를 설정하면서 생성한 인증서다. 2. nginx.conf events {} http { upstream app { server 172.17.0.1:8080; } server { listen 80; server_name hy-notice.kro.kr; return 307 https://$host$request_uri; } server { listen 443 ssl; server_name hy-notice.kro.kr; ssl_certificate /etc/letsencrypt/live/hy-notice.kro.kr/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/hy-notice.kro.kr/privkey.pem; # Disable SSL ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # 통신과정에서 사용할 암호화 알고리즘 ssl_prefer_server_ciphers on; ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!...

2024-09-15 · 1 min · 201 words

DNS 지정하기

resolver nginx config 파일에서 resolver 디렉티브를 사용하면, 사용할 DNS 서버 주소를 지정할 수 있다. 아래 예시는 로컬에 있는 DNS 서버를 사용하겠다는 의미이다. port를 지정하지 않으면 기본적으로 53번 포트를 사용하고, 2개 이상 명시하면 라운드 로빈 방식으로 사용한다. resolver 127.0.0.1 참고 자료 http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver https://wooono.tistory.com/685

2024-09-15 · 1 min · 42 words

414 URI Too Large 해결

문제 상황 GET 요청에 query가 길어지면서, URI가 길어지니 Nginx에서 414 URI Too Large가 발생했다. 원인 분석 Nginx에는 large_client_header_buffers number size 설정값이 존재한다. 요청 헤더를 읽을 때 사용할 버퍼의 개수와 크기를 설정한다. request line이 버퍼 하나의 크기를 초과하면 414 응답이 발생한다. requet line: 요청 메시지의 첫번 째 줄 예시: GET /software/htp/cics/index.html HTTP/1.1 요청 헤더가 버퍼 하나 크기를 초과하면 400 응답이 발생한다. 기본값은 number=4, size=8k 다. 해결 방법 large_client_header_buffers 설정 값을 조절하여 해결한다....

2024-09-15 · 1 min · 97 words