316 lines
16 KiB
Nginx Configuration File
316 lines
16 KiB
Nginx Configuration File
# For more information on configuration, see:
|
||
# * Official English Documentation: http://nginx.org/en/docs/
|
||
# 修改文件中#TODO 的地方,建议使用visual studio code + 安装nginx formatter插件,打开进行编辑格式化
|
||
|
||
# 运行用户,默认即是nginx,可不设置
|
||
user nginx;
|
||
|
||
# nginx进程,一般设置为和cpu核数一样
|
||
worker_processes auto;
|
||
|
||
# TODO 需要全局替换/var/log/nginx/ 为你的Linux安装nginx的路径
|
||
# 全局错误日志定义类型,[ debug | info | notice | warn | error | crit ]
|
||
error_log /var/log/nginx/error.log error;
|
||
|
||
# TODO 需要全局替换/var/run/ 为你想要保存Pid的路径
|
||
# 进程pid文件
|
||
pid /var/run/nginx.pid;
|
||
|
||
# 一个nginx进程打开的最多文件描述符数目,理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以建议与ulimit -n的值保持一致。
|
||
worker_rlimit_nofile 65535;
|
||
|
||
# cpu亲和力配置,让不同的进程使用不同的cpu
|
||
# worker_cpu_affinity 0001 0010 0100 1000 0001 00100100 1000;
|
||
|
||
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
|
||
# TODO
|
||
include /usr/share/nginx/modules/*.conf;
|
||
|
||
# 工作模式及连接数上限
|
||
events {
|
||
# 单个进程最大连接数(最大连接数=连接数*进程数)
|
||
# 根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行。每个进程允许的最多连接数,理论上每台nginx服务器的最大连接数为。
|
||
worker_connections 1024;
|
||
|
||
# 【说明】下面的注释掉可不用,使用默认的
|
||
# #参考事件模型,use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
|
||
# #epoll模型是Linux 2.6以上版本内核中的高性能网络I/O模型,如果跑在FreeBSD上面,就用kqueue模型。
|
||
# #补充说明:
|
||
# #与apache相类,nginx针对不同的操作系统,有不同的事件模型
|
||
# #A)标准事件模型
|
||
# #Select、poll属于标准事件模型,如果当前系统不存在更有效的方法,nginx会选择select或poll
|
||
# #B)高效事件模型
|
||
# #Kqueue:使用于FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 和 MacOS X.使用双处理器的MacOS X系统使用kqueue可能会造成内核崩溃。
|
||
# #Epoll:使用于Linux内核2.6版本及以后的系统。
|
||
# #/dev/poll:使用于Solaris 7 11/99+,HP/UX 11.22+ (eventport),IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+。
|
||
# #Eventport:使用于Solaris 10。 为了防止出现内核崩溃的问题, 有必要安装安全补丁。
|
||
# use epoll;
|
||
|
||
# #单个进程最大连接数(最大连接数=连接数*进程数)
|
||
# #根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行。每个进程允许的最多连接数,理论上每台nginx服务器的最大连接数为。
|
||
# worker_connections 1024;
|
||
# #keepalive超时时间。
|
||
# keepalive_timeout 60;
|
||
# #客户端请求头部的缓冲区大小。这个可以根据你的系统分页大小来设置,一般一个请求头的大小不会超过1k,不过由于一般系统分页都要大于1k,所以这里设置为分页大小。
|
||
# #分页大小可以用命令getconf PAGESIZE 取得。
|
||
# #[root@web001 ~]# getconf PAGESIZE
|
||
# #4096
|
||
# #但也有client_header_buffer_size超过4k的情况,但是client_header_buffer_size该值必须设置为“系统分页大小”的整倍数。
|
||
# client_header_buffer_size 4k;
|
||
# #这个将为打开文件指定缓存,默认是没有启用的,max指定缓存数量,建议和打开文件数一致,inactive是指经过多长时间文件没被请求后删除缓存。
|
||
# open_file_cache max=65535 inactive=60s;
|
||
# #这个是指多长时间检查一次缓存的有效信息。
|
||
# #语法:open_file_cache_valid time 默认值:open_file_cache_valid 60 使用字段:http, server, location 这个指令指定了何时需要检查open_file_cache中缓存项目的有效信息.
|
||
# open_file_cache_valid 80s;
|
||
# #open_file_cache指令中的inactive参数时间内文件的最少使用次数,如果超过这个数字,文件描述符一直是在缓存中打开的,如上例,如果有一个文件在inactive时间内一次没被使用,它将被移除。
|
||
# #语法:open_file_cache_min_uses number 默认值:open_file_cache_min_uses 1 使用字段:http, server, location 这个指令指定了在open_file_cache指令无效的参数中一定的时间范围内可以使用的最小文件数,如果使用更大的值,文件描述符在cache中总是打开状态.
|
||
# open_file_cache_min_uses 1;
|
||
# #语法:open_file_cache_errors on | off 默认值:open_file_cache_errors off 使用字段:http, server, location 这个指令指定是否在搜索一个文件是记录cache错误.
|
||
# open_file_cache_errors on;
|
||
}
|
||
|
||
###################################################
|
||
# 设定http服务器
|
||
http {
|
||
# TODO 可能需要修改/etc/nginx/ 为你安装的路径
|
||
include /etc/nginx/mime.types; #文件扩展名与文件类型映射表
|
||
default_type application/octet-stream; #默认文件类型
|
||
charset utf-8; #默认编码
|
||
|
||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
||
'$status $body_bytes_sent "$http_referer" '
|
||
'"$http_user_agent" "$http_x_forwarded_for"';
|
||
# TODO
|
||
access_log /var/log/nginx/access.log main;
|
||
|
||
# Load modular configuration files from the /etc/nginx/conf.d directory.
|
||
# See http://nginx.org/en/docs/ngx_core_module.html#include
|
||
# for more information.
|
||
include /etc/nginx/conf.d/*.conf;
|
||
|
||
# 服务器名字的hash表大小
|
||
# 保存服务器名字的hash表是由指令server_names_hash_max_size 和server_names_hash_bucket_size所控制的。参数hash bucket size总是等于hash表的大小,并且是一路处理器缓存大小的倍数。在减少了在内存中的存取次数后,使在处理器中加速查找hash表键值成为可能。如果hash bucket size等于一路处理器缓存的大小,那么在查找键的时候,最坏的情况下在内存中查找的次数为2。第一次是确定存储单元的地址,第二次是在存储单元中查找键 值。因此,如果Nginx给出需要增大hash max size 或 hash bucket size的提示,那么首要的是增大前一个参数的大小.
|
||
server_names_hash_bucket_size 128;
|
||
# 客户端请求头部的缓冲区大小。这个可以根据你的系统分页大小来设置,一般一个请求的头部大小不会超过1k,不过由于一般系统分页都要大于1k,所以这里设置为分页大小。分页大小可以用命令getconf PAGESIZE取得。
|
||
client_header_buffer_size 32k;
|
||
# 客户请求头缓冲大小。nginx默认会用client_header_buffer_size这个buffer来读取header值,如果header过大,它会使用large_client_header_buffers来读取。
|
||
large_client_header_buffers 4 64k;
|
||
# 设定通过nginx上传文件的大小
|
||
client_max_body_size 8m;
|
||
|
||
# 开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,
|
||
# 对于普通应用设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。
|
||
# 注意:如果图片显示不正常把这个改成off。
|
||
sendfile on;
|
||
keepalive_timeout 120; #长连接超时时间,单位是秒
|
||
types_hash_max_size 2048;
|
||
|
||
# 开启目录列表访问,合适下载服务器,默认关闭。
|
||
# autoindex on;
|
||
# 此选项允许或禁止使用socke的TCP_CORK的选项,此选项仅在使用sendfile的时候使用
|
||
tcp_nopush on;
|
||
tcp_nodelay on;
|
||
|
||
# FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。下面参数看字面意思都能理解。
|
||
fastcgi_connect_timeout 300;
|
||
fastcgi_send_timeout 300;
|
||
fastcgi_read_timeout 300;
|
||
fastcgi_buffer_size 64k;
|
||
fastcgi_buffers 4 64k;
|
||
fastcgi_busy_buffers_size 128k;
|
||
fastcgi_temp_file_write_size 128k;
|
||
|
||
# #gzip模块设置
|
||
# gzip on; #开启gzip压缩输出
|
||
# gzip_min_length 1k; #最小压缩文件大小
|
||
# gzip_buffers 4 16k; #压缩缓冲区
|
||
# gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
|
||
# gzip_comp_level 2; #压缩等级
|
||
# gzip_types text/plain application/x-javascript text/css application/xml;
|
||
# #压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
|
||
# gzip_vary on;
|
||
|
||
# 开启限制IP连接数的时候需要使用
|
||
# limit_zone crawler $binary_remote_addr 10m;
|
||
# upstream的负载均衡,weight是权重,可以根据机器配置定义权重。weigth参数表示权值,权值越高被分配到的几率越大。
|
||
# nginx的upstream目前支持4种方式的分配
|
||
# 1、轮询(默认)
|
||
# 每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除。
|
||
# 2、weight
|
||
# 指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况。
|
||
# 例如:
|
||
# upstream bakend {
|
||
# server 192.168.0.14 weight=10;
|
||
# server 192.168.0.15 weight=10;
|
||
# }
|
||
# 2、ip_hash
|
||
# 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
|
||
# 例如:
|
||
# upstream bakend {
|
||
# ip_hash;
|
||
# server 192.168.0.14:88;
|
||
# server 192.168.0.15:80;
|
||
# }
|
||
# 3、fair(第三方)
|
||
# 按后端服务器的响应时间来分配请求,响应时间短的优先分配。
|
||
# upstream backend {
|
||
# server server1;
|
||
# server server2;
|
||
# fair;
|
||
# }
|
||
# 4、url_hash(第三方)
|
||
# 按访问url的hash结果来分配请求,使每个url定向到同一个后端服务器,后端服务器为缓存时比较有效。
|
||
# 例:在upstream中加入hash语句,server语句中不能写入weight等其他的参数,hash_method是使用的hash算法
|
||
# upstream backend {
|
||
# server squid1:3128;
|
||
# server squid2:3128;
|
||
# hash $request_uri;
|
||
# hash_method crc32;
|
||
# }
|
||
#
|
||
# tips:
|
||
# upstream bakend{#定义负载均衡设备的Ip及设备状态}{
|
||
# ip_hash;
|
||
# server 127.0.0.1:9090 down;
|
||
# server 127.0.0.1:8080 weight=2;
|
||
# server 127.0.0.1:6060;
|
||
# server 127.0.0.1:7070 backup;
|
||
# }
|
||
# 在需要使用负载均衡的server中增加 proxy_pass http://bakend/;
|
||
# 每个设备的状态设置为:
|
||
# 1. down表示单前的server暂时不参与负载
|
||
# 2. weight为weight越大,负载的权重就越大。
|
||
# 3. max_fails:允许请求失败的次数默认为1.当超过最大次数时,返回proxy_next_upstream模块定义的错误
|
||
# 4. fail_timeout:max_fails次失败后,暂停的时间。
|
||
# 5. backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。所以这台机器压力会最轻。
|
||
# nginx支持同时设置多组的负载均衡,用来给不用的server来使用。
|
||
# client_body_in_file_only设置为On 可以讲client post过来的数据记录到文件中用来做debug
|
||
# client_body_temp_path设置记录文件的目录 可以设置最多3层目录
|
||
# location对URL进行匹配.可以进行重定向或者进行新的代理 负载均衡
|
||
upstream flowmoney {
|
||
ip_hash;
|
||
server 0.0.0.0:8188 weight=2;
|
||
server 80.240.22.253:8188 weight=3;
|
||
}
|
||
upstream text_nlp {
|
||
server 0.0.0.0:8188;
|
||
}
|
||
|
||
#虚拟主机的配置
|
||
server {
|
||
#监听端口
|
||
listen 80;
|
||
#域名可以有多个,用空格隔开
|
||
server_name 0.0.0.0 www.flowmoney.top;
|
||
charset utf-8;
|
||
root /usr/share/nginx/html;
|
||
|
||
#对 "/" 启用反向代理
|
||
# 即打开网址的默认页面,如:http://flowmoney.top/
|
||
location / {
|
||
# 这里没有设置的话,会默认读取nignx自带的展示html配置路径
|
||
# /usr/share/nginx/html/ (这个路径也可以上传自己的html文件)
|
||
|
||
# 例子,Django项目的设置
|
||
# include /usr/local/etc/nginx/uwsgi_params; # TODO 修改
|
||
# uwsgi_connect_timeout 600; #指定向uWSGI传送请求的超时时间,完成握手后向uWSGI传送请求的超时时间
|
||
# uwsgi_send_timeout 600; #连接到后端uWSGI的超时时间
|
||
# uwsgi_read_timeout 600; #指定接收uWSGI应答的超时时间,完成握手后接收uWSGI应答的超时时间
|
||
# uwsgi_pass unix:/Users/xxx/uwsgi.sock; #这个是项目的绝对路径
|
||
# index index.html index.htm;
|
||
# client_max_body_size 300M;
|
||
# proxy_read_timeout 600;
|
||
|
||
}
|
||
|
||
location /static {
|
||
alias /root/Text-Auto-Summarization/static;
|
||
index index.html index.htm;
|
||
}
|
||
|
||
location /TextSummarization {
|
||
proxy_pass http://text_nlp;
|
||
}
|
||
|
||
error_page 404 /404.html;
|
||
location = /40x.html {
|
||
}
|
||
|
||
error_page 500 502 503 504 /50x.html;
|
||
location = /50x.html {
|
||
}
|
||
|
||
# #图片缓存时间设置
|
||
# location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ {
|
||
# expires 10d;
|
||
# }
|
||
# #所有静态文件由nginx直接读取不经过tomcat或resin
|
||
# location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|
|
||
# pdf|xls|mp3|wma)$ {
|
||
# expires 15d;
|
||
# }
|
||
# #JS和CSS缓存时间设置
|
||
# location ~ .*.(js|css)?$ {
|
||
# expires 1h;
|
||
# }
|
||
# #设定查看Nginx状态的地址
|
||
# location /NginxStatus {
|
||
# stub_status on;
|
||
# access_log on;
|
||
# auth_basic "NginxStatus";
|
||
# auth_basic_user_file confpasswd;
|
||
# #htpasswd文件的内容可以用apache提供的htpasswd工具来产生。
|
||
# }
|
||
# #本地动静分离反向代理配置
|
||
# #所有jsp的页面均交由tomcat或resin处理
|
||
# location ~ .(jsp|jspx|do)?$ {
|
||
# proxy_set_header Host $host;
|
||
# proxy_set_header X-Real-IP $remote_addr;
|
||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||
# proxy_pass http://127.0.0.1:8080;
|
||
# }
|
||
|
||
# 日志格式设定
|
||
#$remote_addr与$http_x_forwarded_for用以记录客户端的ip地址;
|
||
#$remote_user:用来记录客户端用户名称;
|
||
#$time_local: 用来记录访问时间与时区;
|
||
#$request: 用来记录请求的url与http协议;
|
||
#$status: 用来记录请求状态;成功是200,
|
||
#$body_bytes_sent :记录发送给客户端文件主体内容大小;
|
||
#$http_referer:用来记录从那个页面链接访问过来的;
|
||
#$http_user_agent:记录客户浏览器的相关信息;
|
||
#通常web服务器放在反向代理的后面,这样就不能获取到客户的IP地址了,通过$remote_add拿到的IP地址是反向代理服务器的iP地址。反向代理服务器在转发请求的http头信息中,可以增加x_forwarded_for信息,用以记录原有客户端的IP地址和原来客户端的请求的服务器地址。
|
||
# log_format access '$remote_addr - $remote_user [$time_local] "$request" '
|
||
# '$status $body_bytes_sent "$http_referer" '
|
||
# '"$http_user_agent" $http_x_forwarded_for';
|
||
# #定义本虚拟主机的访问日志
|
||
# access_log /usr/local/nginx/logs/host.access.log main;
|
||
# access_log /usr/local/nginx/logs/host.access.404.log log404;
|
||
}
|
||
|
||
# 配置https
|
||
server {
|
||
listen 443 ssl http2;
|
||
server_name www.flowmoney.top;
|
||
ssl_certificate /root/.acme.sh/flowmoney.top/flowmoney.top.csr;
|
||
ssl_certificate_key /root/.acme.sh/flowmoney.top/flowmoney.top.key;
|
||
charset utf-8;
|
||
root /usr/share/nginx/html;
|
||
|
||
#对 "/" 启用反向代理
|
||
# 即打开网址的默认页面,如:http://flowmoney.top/
|
||
location / {
|
||
# 这里没有设置的话,会默认读取nignx自带的展示html配置路径
|
||
# /usr/share/nginx/html/ (这个路径也可以上传自己的html文件)
|
||
}
|
||
|
||
location /static {
|
||
alias /root/Text-Auto-Summarization/static;
|
||
index index.html index.htm;
|
||
}
|
||
|
||
location /TextSummarization {
|
||
proxy_pass http://text_nlp;
|
||
}
|
||
}
|
||
} |