NodeBB Nginx Configuration Optimization 엔진엑스 성능 최적화
-
Nodebb 성능 최적화를 위한 빠른 요약
Nginx는 정적 파일을 직접 제공하고, 동적 요청은 Node.js 서버로 프록시
location @nodebb { proxy_pass http://nodes; } location ~ ^/(assets|plugins)/(.*) { root /usr/share/nginx/build/public; try_files $uri /src/$uri @nodebb; } location / { try_files $uri @nodebb; proxy_pass http://nodes; }
docker-compose.yml
nginx: container_name: nginx-nodebb image: navystack/openresty:1.25.3 logging: driver: json-file options: tag: '{{.ImageName}}|{{.Name}}|{{.ImageFullID}}|{{.FullID}}' max-size: '10m' max-file: 100 restart: unless-stopped volumes: - nodebb-build:/usr/share/nginx/build - nodebb-uploads:/usr/share/nginx/public/uploads - ./nginx:/etc/nginx/conf.d/ - ./nginx-etc/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf networks: - internal - traefik-network depends_on: - nodebb
default.conf
upstream nodes { ip_hash; server nodebb-askfront:4567; keepalive 2; } server { listen 80; server_name _; more_set_headers 'Server: OCI-QUN'; set_real_ip_from 0.0.0.0/0; real_ip_header X-Forwarded-For; real_ip_recursive on; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-Forwarded-Proto https; proxy_hide_header X-Powered-By; proxy_hide_header X-Dns-Prefetch-Control; proxy_hide_header X-Download-Options; proxy_set_header Content-Disposition "attachment"; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; # Gzip Settings gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 1; gzip_buffers 16 8k; gzip_http_version 1.1; gzip_min_length 1024; gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss image/svg+xml; # Brotli Settings brotli on; brotli_comp_level 6; brotli_static on; brotli_min_length 1024; brotli_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/xml+rss image/svg+xml; location @nodebb { proxy_pass http://nodes; } location ~ ^/(assets|plugins)/(.*) { root /usr/share/nginx/build/public; try_files $uri /src/$uri @nodebb; } location / { try_files $uri @nodebb; proxy_pass http://nodes; } }
-
upstream nodes
: Node.js 서버의 업스트림을 정의.
ip_hash
는 세션 퍼시스턴스를 제공하기 위해 클라이언트 IP를 기반으로 한 서버로 트래픽을 라우팅 -
server
: HTTP 서버 블록을 정의. 포트 80에서 리스닝하며, 모든 도메인을 허용.
(상황에 맞게 적절하게 수정) -
proxy_set_header
: 프록시로 전달되는 요청 헤더를 설정. 실제 IP 주소와 포트, 프로토콜 등을 설정. -
proxy_hide_header
: 프록시 응답에서 특정 헤더를 숨김. -
proxy_redirect
: 프록시 리디렉션을 비활성화. -
gzip
및brotli
: Gzip 및 Brotli 압축을 사용하여 지정된 MIME 타입의 응답을 압축합니다. (nodebb 자체가 요청 횟수가 많으므로 최대한 적정한 크기만 압축) -
location
블록들: URL 경로에 따라 요청을 처리.
-
location @nodebb
: @nodebb라는 이름의 location 블록으로 요청을 전달.
프록시 패스를 사용하여 Node.js 서버로 요청을 전달. -
location ~ ^/(assets|plugins)/(.*)
: 정규 표현식을 사용하여 URL 경로가 /assets/ 또는 /plugins/로 시작하는 요청을 처리.
이 경우에는 정적 파일을 제공하기 위해 지정된 디렉토리에서 파일을 찾고, 없으면 Node.js 서버로 요청을 전달. -
location /
: 기본적으로 모든 요청은 Node.js 서버로 전달.try_files
지시문을 사용하여 파일이나 디렉토리가 존재하지 않을 경우@nodebb
블록으로 요청을 전달.
-