下载Nginx
下载解压就是Nginx的文件。
Nginx配置
然后去conf
文件夹下打开nginx.conf
创建一个文件
common_server_config.conf
粘贴以下内容
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
# On-disk Brotli-precompressed data files should be served with compression enabled:
location ~ \.(data|symbols\.json)\.br$ {
sendfile off;
gzip off;
add_header Content-Encoding br;
default_type application/octet-stream;
}
# On-disk Brotli-precompressed JavaScript code files:
location ~ \.js\.br$ {
sendfile off;
gzip off;
add_header Content-Encoding br;
default_type application/javascript;
}
# On-disk Brotli-precompressed WebAssembly files:
location ~ \.wasm\.br$ {
sendfile off;
gzip off;
add_header Content-Encoding br;
default_type application/wasm;
}
# On-disk gzip-precompressed data files should be served with compression enabled:
location ~ \.(data|symbols\.json)\.gz$ {
sendfile off;
gzip off;
add_header Content-Encoding gzip;
default_type application/octet-stream;
}
# On-disk gzip-precompressed JavaScript code files:
location ~ \.js\.gz$ {
sendfile off;
gzip off;
add_header Content-Encoding gzip;
default_type application/javascript;
}
# On-disk gzip-precompressed WebAssembly files:
location ~ \.wasm\.gz$ {
sendfile off;
gzip off;
add_header Content-Encoding gzip;
default_type application/wasm;
}
location / {
try_files $uri $uri/ =404;
}
打开nginx.conf
,粘贴以下内容
worker_processes auto;
events {
worker_connections 1024;
}
http {
include mime.types;
sendfile on;
keepalive_timeout 65;
server {
listen 8901;
server_name localhost;
root html;
index index.html index.htm;
#导入相同的配置文件
include common_server_config.conf;
}
}
粘贴完成后双击nginx.exe运行。
在任务管理器中也可以看到运行的nginx.exe
WebGL运行
nginx解压后的文件
打开html文件夹,将webGL文件拷贝进去,这里以后我的一个webGL的测试项目为例子
webGL示例项目的下载地址(优快云)
https://download.youkuaiyun.com/download/GoodCooking/24339451?spm=1001.2014.3001.5503
百度网盘
https://pan.baidu.com/s/1F-hXWwFxyGLiBeV-Tdhq8Q?pwd=mr7i
然后再启动nginx.exe就可以再浏览器的地址栏输入localhost:8901
访问了。
另外一种配置文件
这个是将上面的两个文件nginx.conf
与common_server_config.conf
合并到一个文件了。
使用上面两个文件的方式优点是:当需要使用nginx配置两个文件的时候,不需要复制一遍配置文件,只需要修改nginx.conf 中的文件,再添加一个server块即可。
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 58231;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
# 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/octet-stream;
}
# 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;
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;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
不懂私信,资源没有找我要
。