Unity 웹 빌드에서 Nginx 서버를 사용하도록 Nginx 서버 구성 파일을 설정합니다.
Nginx를 사용하면 Unity로 제작한 웹 콘텐츠를 빠르고 효율적으로 제공할 수 있습니다.
모든 파일 유형 및 압축 유형이 포함된 전체 코드 예시는 모든 파일 유형이 포함된 전체 코드 예시를 참조하십시오.
Nginx 서버와 그 설치 방법에 대한 상세 내용은 Nginx 기술 자료를 참조하십시오.
기존 HTTP 서버 구성 내에 다음 설정을 추가합니다.
http {
# ...
server {
# Nest inside existing location rule
location / {
# ...
이제 빌드에 맞는 코드와 서버에서 사용할 파일 유형 및 압축 유형을 추가할 준비가 되었습니다.
모든 유형의 Brotli 사전 압축 파일이 클라이언트에 효율적으로 제공되도록 하려면 서버 구성에 코드를 추가해야 합니다. 하지만 해당 코드는 파일 유형(데이터 파일, JavaScript 파일 또는 WebAssembly 파일)에 따라 달라집니다.
디스크에 있는 Brotli 사전 압축 데이터 파일(데이터, 심볼, .json 파일)의 경우 다음 코드를 추가합니다.
location ~ .+\.(data|symbols\.json)\.br$ {
gzip off;
add_header Content-Encoding br;
default_type application/octet-stream;
}
이 파일은 디스크에서 이미 사전 압축되었기 때문에 이 코드는 디스크의 온디멘드 압축을 비활성화합니다. 그렇지 않으면 Nginx가 이중 압축을 시도합니다.
디스크에 있는 Brotli 사전 압축 JavaScript 코드 파일의 경우 다음 코드를 추가합니다.
location ~ .+\.js\.br$ {
gzip off; # Do not attempt dynamic gzip compression on an already compressed file
add_header Content-Encoding br;
default_type application/javascript;
}
디스크에 있는 Brotli 사전 압축 WebAssembly 파일의 경우 다음 코드를 추가합니다.
location ~ .+\.wasm\.br$ {
gzip off; # Do not attempt dynamic gzip compression on an already compressed file
add_header Content-Encoding br;
# Enable streaming WebAssembly compilation by specifying the correct MIME type for
# Wasm files.
default_type application/wasm;
}
모든 유형의 gzip 사전 압축 파일이 클라이언트에 효율적으로 제공되도록 하려면 서버 구성에 코드를 추가해야 합니다. 하지만 해당 코드는 파일 유형(데이터 파일, JavaScript 파일 또는 WebAssembly 파일)에 따라 달라집니다.
디스크에 있는 gzip 사전 압축 데이터 파일의 경우 다음 코드를 추가합니다.
location ~ .+\.(data|symbols\.json)\.gz$ {
gzip off; # Do not attempt dynamic gzip compression on an already compressed file
add_header Content-Encoding gzip;
default_type application/gzip;
}
디스크에 있는 gzip 사전 압축 JavaScript 파일의 경우 다음 코드를 추가합니다.
location ~ .+\.js\.gz$ {
gzip off; # Do not attempt dynamic gzip compression on an already compressed file
add_header Content-Encoding gzip; # The correct MIME type here would be application/octet-stream, but due to Safari bug https://bugs.webkit.org/show_bug.cgi?id=247421, it's preferable to use MIME Type application/gzip instead.
default_type application/javascript;
}
디스크에 있는 gzip 사전 압축 WebAssembly 파일의 경우 다음 코드를 추가합니다.
location ~ .+\.wasm\.gz$ {
gzip off; # Do not attempt dynamic gzip compression on an already compressed file
add_header Content-Encoding gzip;
# Enable streaming WebAssembly compilation by specifying the correct MIME type for
# Wasm files.
default_type application/wasm;
}
Player 설정에서 Native C/C++ 멀티스레딩 활성화를 활성화한 경우, 서버 구성에 다음 코드를 추가합니다.
location ~ .+\.(htm|html|js|js\.gz|js\.br)$ {
add_header Cross-Origin-Opener-Policy same-origin;
add_header Cross-Origin-Embedder-Policy require-corp;
add_header Cross-Origin-Resource-Policy cross-origin;
}
CORS(크로스 오리진 리소스 공유)는 웹 애플리케이션이 리소스를 요청하는 방식을 제어하는 웹 브라우저 보안 기능입니다. CORS는 악의적인 웹사이트의 무단 요청을 방지하여 민감한 데이터를 보호하는 데 도움이 됩니다.
서버 상호작용에서 CORS 요청을 허용하려면 구성 파일에 다음 코드를 추가합니다.
add_header Access-Control-Allow-Origin *;
다음은 모든 파일 유형이 추가된 코드 샘플입니다.
http {
# ...
server {
# Add the following config within the existing http server configuration
# Nest inside existing location rule
location / {
# ...
# On-disk Brotli-precompressed data files should be served with compression enabled:
location ~ .+\.(data|symbols\.json)\.br$ {
# Because this file is already pre-compressed on disk, disable the on-demand compression on it.
# Otherwise nginx would attempt double compression.
gzip off;
add_header Content-Encoding br;
default_type application/octet-stream;
}
# On-disk Brotli-precompressed JavaScript code files:
location ~ .+\.js\.br$ {
gzip off; # Do not attempt dynamic gzip compression on an already compressed file
add_header Content-Encoding br;
default_type application/javascript;
}
# On-disk Brotli-precompressed WebAssembly files:
location ~ .+\.wasm\.br$ {
gzip off; # Do not attempt dynamic gzip compression on an already compressed file
add_header Content-Encoding br;
# Enable streaming WebAssembly compilation by specifying the correct MIME type for
# Wasm files.
default_type application/wasm;
}
# On-disk gzip-precompressed data files should be served with compression enabled:
location ~ .+\.(data|symbols\.json)\.gz$ {
gzip off; # Do not attempt dynamic gzip compression on an already compressed file
add_header Content-Encoding gzip;
default_type application/gzip;
}
# On-disk gzip-precompressed JavaScript code files:
location ~ .+\.js\.gz$ {
gzip off; # Do not attempt dynamic gzip compression on an already compressed file
add_header Content-Encoding gzip; # The correct MIME type here would be application/octet-stream, but due to Safari bug https://bugs.webkit.org/show_bug.cgi?id=247421, it's preferable to use MIME Type application/gzip instead.
default_type application/javascript;
}
# On-disk gzip-precompressed WebAssembly files:
location ~ .+\.wasm\.gz$ {
gzip off; # Do not attempt dynamic gzip compression on an already compressed file
add_header Content-Encoding gzip;
# Enable streaming WebAssembly compilation by specifying the correct MIME type for
# Wasm files.
default_type application/wasm;
}
# Uncomment the following lines if build was created with "Enable Native C/C++ Multithreading" player settings
# location ~ .+\.(htm|html|js|js\.gz|js\.br)$ {
# add_header Cross-Origin-Opener-Policy same-origin;
# add_header Cross-Origin-Embedder-Policy require-corp;
# add_header Cross-Origin-Resource-Policy cross-origin;
# }
# Uncomment the following line to allow CORS requests
# add_header Access-Control-Allow-Origin *;
}
}
}