#用于指定 Nginx 进程运行的用户和用户组,root 用户具有系统的最高权限(潜在的安全漏洞)可以用use nginx=>非特权用户(通常是 nginx)的身份运行
user root;
#Nginx服务器能够同时处理的连接数量(设置服务器cpu核数),每个进程是相互独立的,可以并行处理请求,从而提高Nginx 的并发能力和性能
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;#pid logs/nginx.pid;events {#每个进程可以同时打开的最大连接数worker_connections 1024;
}#RTMP协议配置。用于流媒体传输。该配置使用 Nginx 的 rtmp 模块来支持 RTMP 协议。
rtmp {server {listen 1935; #监听端口#用于实时直播的应用程序。application live {live on; #允许客户端通过 RTMP 协议进行实时直播流传输}#用于实时直播流的HLS应用程序application hls {live on; #允许客户端进行实时直播流传输hls on; #启用 HLS功能,HLS 是一种流媒体传输协议hls_path /usr/local/nginx/html/hls; #指定了 HLS 切片的存放路径hls_fragment 1s; #本地切片长度hls_playlist_length 4s; #HLS播放列表长度}}
}#http配置
http {#用于引入一个外部文件 mime.types,在当前配置文件目录下有mime.types文件,可以确保服务器正确地处理文件的 MIME 类型,从而保证文件能够以正确的方式传输和呈现给客户端。#mime.types里面有MIME 类型的映射关系,include mime.types; #默认#指令用于设置当服务器无法确定文件的 MIME 类型时的默认类型default_type application/octet-stream; #默认#限制请求体的大小,若超过所设定的大小,返回413错误client_max_body_size 300M;#设置日志的记录格式log_format json '{\"remote_addr\": \"$remote_addr\",''\"remote_user\": \"$remote_user\",''\"request\": \"$request\",''\"status\": \"$status\",''\"body_bytes_sent\": \"$body_bytes_sent\",''\"http_referer\": \"$http_referer\",''\"http_user_agent\": \"$http_user_agent\",''\"http_x_forwarded_for\": \"$http_x_forwarded_for\"''}';#日志文件的存放路径,格式access_log logs/access.log json;sendfile on;#tcp_nopush on;upstream mysvr { #192.168.0.42:80服务地址server 192.168.0.42:80 max_fails=2 fail_timeout=30; #当服务器连续失败的次数达到 2 次时,Nginx 将认为该服务器暂时不可用,在 30 秒内不再发送请求到该服务器}client_body_timeout 1800; #客户端请求体的超时时间,即客户端发送请求体的最大时间间隔#keepalive_timeout 0;keepalive_timeout 1800; #持久连接的超时时间,在没有新的请求到达服务器的情况下,服务器将保持连接打开的时间长度proxy_connect_timeout 1800; #nginx跟后端服务器连接超时时间(代理连接超时)proxy_send_timeout 1800; #向后端服务器发送请求的超时时间。如果在指定的时间内无法完成请求的发送,将视为发送超时proxy_read_timeout 1800; #连接成功后,后端服务器响应时间,若此时间内没接到响应,则响应超时#gzip on;send_timeout 360; #发送响应给客户端的超时时间为360秒。如果在指定的时间内无法完成响应的发送,将视为发送超时#topology的配置页面的配置server {listen 3000; #端口server_name 192.168.0.42; #客户端请求的域名或主机名# 处理根路径 / 的请求location / {root /opt/topology/dist; #topolopy的前端包所放的目录。index index.html index.htm; #当请求的路径是目录时,默认返回的文件名为 index.html 或 index.htm。默认try_files $uri $uri/ /index.html; #定义文件检查和重定向规则。先匹配 $uri,如果文件不存在,则尝试匹配 $uri/,最后如果都失败,则返回 /index.html}# 以 /group[1-9]/M00 开头的请求配置location ~/group[1-9]/M00 {root /opt/fdfs/storage/data; #静态文件所在的根目录ngx_fastdfs_module; #处理 FastDFS 文件存储系统的请求(Nginx 第三方模块)。该模块需要事先安装和配置}# 处理workspace/group1/开头的请求location /workspace/group1/ {proxy_pass http://mysvr/user/; #将请求转发到 http://mysvr/user/ 的目标服务器}location /user/ {proxy_pass http://mysvr/user/;}location /place/ {proxy_pass http://mysvr/place/;}location /fastdfs/ {proxy_pass http://mysvr/fastdfs/;}location /asset/ {proxy_pass http://mysvr/asset/;}location /ffmpeg/ {proxy_pass http://mysvr/ffmpeg/;}}server {listen 80;server_name 192.168.0.42;location / { root /opt/dist; #dcim的前端包地址index index.html index.htm;try_files $uri $uri/ /index.html;}location ~/group[1-9]/M00 {#root /usr/fastdfs/storage/data;root /usr/local/fastdfs/fastdfs-6.07/storage/data;ngx_fastdfs_module;}location /dcim-api/ {proxy_pass http://mysvr/dcim-api/; # 将请求转发到 http://mysvr/dcim-api/ 如果端口80,的携带dcim-api/。端口不是80则proxy_pass http://mysvr/; proxy_set_header Host $host:$server_port; # 设置代理请求的头部信息,包括 Host 头部proxy_connect_timeout 600; #设置代理连接超时时间proxy_read_timeout 600; #设置代理读取超时时间proxy_send_timeout 600; #设置代理发送超时时间}#自定义报表,不需要可删除,若使用记得改这里的IP地址location /api/ {proxy_pass http://192.168.0.42:5000/api/;proxy_set_header Host $host:$server_port;proxy_connect_timeout 200; proxy_read_timeout 200;proxy_send_timeout 200;}location /hls {#定义了响应的 MIME 类型types{application/vnd.apple.mpegurl m3u8; video/mp2t ts; }alias /usr/local/nginx/html/hls; #将请求映射到 /usr/local/nginx/html/hls 目录下的文件expires -1; #设置响应头中的 Expires 字段为过去的一个时间,即禁用缓存}#指定当出现 500、502、503 或 504 错误时,跳转到 /50x.html 页面error_page 500 502 503 504 /50x.html;#指定处理 /50x.html 路径的请求location = /50x.html {root html; #将 /50x.html 映射到 html 目录下的文件}}# another virtual host using mix of IP-, name-, and port-based configuration#下载文件(回放)server {listen 8001;server_name 192.168.0.42;# 以/downloadFile/ 开头的请求映射到 /root/image/downloadFile/ 目录下的文件,并提供下载功能location /downloadFile/ { alias /root/image/downloadFile/; #需要下载的文件存放的目录sendfile on; #开启 Nginx 的 sendfile 功能,用于高效地传输文件autoindex on; # 开启目录文件列表autoindex_exact_size on; # 显示出文件的确切大小,单位是bytesautoindex_localtime on; # 显示的文件时间为文件的服务器时间charset utf-8,gbk; # 避免中文乱码}}}