Nginx配置文件(nginx.conf)配置详解
2023-06-13 09:13:14 时间
仅做参考
user root;
#Nginx用户及组:用户 组。window下不指定
worker_processes 1;
#工作进程:数目。根据硬件调整,通常等于CPU数量或者2倍于CPU。
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
#错误日志:存放路径。
pid logs/nginx.pid;
#pid(进程标识符):存放路径。
events {
worker_connections 1024;
#没个工作进程的最大连接数量。根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行。
#每个进程允许的最多连接数,理论上每台nginx服务器的最大连接数为。worker_processes*worker_connections
open_file_cache_valid 80s;
#这个是指多长时间检查一次缓存的有效信息。
keepalive_timeout 60;
#连接超时时间。
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
include mime.types;
#设定mime类型,类型由mime.type文件定义
default_type application/octet-stream;
client_max_body_size 20m;
#这个类型会让浏览器认为响应是普通的文件流,并提示用户下载文件。可以通过在Nginx的配置文件中做如下配置达到这样的目的。
sendfile on;
#sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,
#对于普通应用,必须设为 on,
#如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,
#以平衡磁盘与网络I/O处理速度,降低系统的uptime.
keepalive_timeout 65;
#连接超时时间。
limit_conn_zone $server_name zone=mylimitzone:10m;
#指令描述会话状态存储区域。
#会话的数目按照指定的变量来决定,它依赖于使用的变量大小和memory_max_size的值。
server_tokens off;
#隐藏版本号。
rewrite_log on;
# 开启重写日志
log_format main escape=json
#日志格式定义
'remote_addr -$remote_addr : $remote_user $server_name [$time_local] "$request" '
'$status $body_bytes_sent "$request_body" "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"Content-Type=$http_content_type" "heard_host0=$host" "heard_host1=$http_host"' '"HTTP_X_FORWARDED_FOR=$HTTP_X_FORWARDED_FOR"'
'""';
server {
listen 8096;
server_name localhost;
location / {
alias /root/syncFiles/mbank/app;
limit_conn mylimitzone 10;
limit_rate 1024k;
}
}
server {
listen 8097;
server_name localhost;
location / {
access_log logs/mbankStatic.log main;
alias /root/syncFiles/mbank/app/;
limit_conn mylimitzone 10;
limit_rate 1024k;
}
#手机端接口调用
location /mbankAPI/ {
#自定义日志文件
access_log logs/mabankAPI.log main;
proxy_pass http://172.17.54.47:8888/;
index index.html index.htm;
}
}
server {
listen 8098;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /syncFiles {
alias /root/syncFiles;
limit_conn mylimitzone 10;
limit_rate 1024k;
}
}
server {
listen 8099;
server_name localhost;
#gzip配置
#开启Nginx Gzip压缩
gzip on;
#只有超过100k的文件才压缩
gzip_min_length 100k;
#image/jpeg类似的图片文件本身就已经时经过压缩的文件,gzip对于文本文件的效果极好
gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php;
#低版本IE禁用Gzip压缩
gzip_disable "MSIE[1-6]\.";
#压缩使用的缓存,每个内存页为4k,申请32倍
gzip_buffers 32 4k;
#设置压缩级别1-9,越大压缩比例越高,但浪费的CPU资源也越多,建议1-4即可
gzip_comp_level 6;
gzip_vary on;
gzip_http_version 1.0;
location /eeeeeeee {
alias /home/fffffffffffffff/;
limit_conn mylimitzone 10;
limit_rate 1024k;
}
location /aaaaaaa {
alias /root/eeeeeeeeeeeee;
limit_conn mylimitzone 10;
limit_rate 1024k;
}
}
}
Post Views: 211
相关文章
- 重识Nginx - 03 Nginx配置语法
- nginx配置访问本地静态资源
- shiro框架—shiro配置介绍(一)
- nginx禁止ip访问,允许域名访问如何配置
- Nginx配置中root和alias分不清?本文3分钟帮你解惑!
- nginx rewrite伪静态配置参数详解
- OpenSupports 在 NGINX 下的配置
- Nginx的负载均衡配置教程
- 如何linux环境下配置环境变量过程图解
- nginx服务的基本配置详解程序员
- Centos下Nginx配置WEB访问日志并结合shell脚本定时切割详解程序员
- linux下nginx配置ssl证书(https)详解程序员
- Linux系统关闭Nginx服务器(linux关闭nginx)
- 配置Linux下快速删除Nginx配置的技巧(linux删除nginx)
- Nginx网站架构实战——15、nginx实现负载均衡
- Nginx主配置文件nginx.conf详解
- Nginx安全配置研究
- 深入学习:Linux下Java环境建设与配置(linux下java环境)
- 实施MySQL集群:从安装到配置(mysql集群安装配置)
- nginx秒杀科技Redis与Nginx结合的方案(秒杀技术方案redis和)
- 在nginx中配置pathinfo模式支持thinkphp的URL重写
- Nginx中禁止使用IP访问网站的配置实例