Nginx干货(二)配置详解
来源:互联网 发布:怎么把域名和空间绑定 编辑:程序博客网 时间:2024/06/02 02:59
Nginx干货(二)配置详解
此篇就不矫情了。直接上个配置吧。以后若有更新,继续修补
- /usr/local/nginx/conf目录下面的nginx.conf文件
以用户nginx的身份来运行
user nginx;
启动进程,通常设置成和cpu数量相等
worker_processes 10;
全局错误日志
error_log logs/error.log;error_log logs/error.log notice;error_log logs/error.log info;
Pid文件存放路径
pid /var/run/nginx.pid;
工作模式及连接数上限设置
events { # epoll是多路复用IO(I/O Multiplexing)中的一种方式 支持linux2.6以上内核 use epoll; # 单个后台worker process进程最大并发连接数 worker_connections 1024; # 优化同一时刻只有一个请求而避免多个睡眠进程被唤醒的设置,on为防止被同时唤醒,默认为off,因此nginx刚安装完以后要进行适当的优化。 accept_mutex on; # 打开同时接受多个新网络连接请求的功能。 multi_accept on;}
设置http服务器
http { # 隐藏nginx版本号 server_tokens off; # 文件扩展名与文件类型映射表 include mime.types; # 默认文件类型 default_type application/octet-stream; # 设置日志格式 access_log /var/log/nginx/access.log; # 请求体最大容量 client_max_body_size 500M; # 开启高效文件传输模式 sendfile on; # 长连接超时时间 单位秒 keepalive_timeout 65; # 开启gzip压缩 gzip on; # 设定请求缓冲 client_header_buffer_size 1k; large_client_header_buffers 4 4k; # 引入外部配置文件 include /usr/local/nginx/conf/conf.d/*.conf; # FastCGI相关参数是为了改善网站的性能:减少资源占用,提高访问速度。 fastcgi_connect_timeout 900; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 128k; fastcgi_buffers 2 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k;}
- /usr/local/nginx/conf.d目录(注,此目录是小轩自己创建的哟)
a.conf文件
代理tomcat
upstream tomcat-servers {
# weight代表权重的意思,当前配置也是一个代理tomcat集群的配置,当前使用的方式是权重方式,除此之外还有轮询的方式还有基于ip分配等多种方式。
server 192.168.1.11:8080 weight 1;
server 192.168.1.12:8080 weight 6;
}
server配置
server { # 端口监听 listen 80; # 基于域名的方式分配虚拟主机 server_name xxxxxxxxx.com; # 拦截路径 location /HanYiAPP_SystemManage { # 注意如果这里项目的context-path不为"/"则“http://tomcat-servers/project” project为项目的context-path proxy_pass http://tomcat-servers; proxy_redirect off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; # 容灾处理 proxy_next_upstream http_502 http_504 error timeout invalid_header; #nginx跟后端服务器连接超时时间(代理连接超时) proxy_connect_timeout 600; #连接成功后,后端服务器响应时间(代理接收超时) proxy_read_timeout 600; #后端服务器数据回传时间(代理发送超时) proxy_send_timeout 600; #设置代理服务器(nginx)保存用户头信息的缓冲区大小 proxy_buffer_size 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置 proxy_buffers 4 32k; #高负荷下缓冲大小(proxy_buffers*2) proxy_busy_buffers_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传 proxy_temp_file_write_size 64k; } #文件服务器 location /file { # 允许跨域请求。所有连接都可跨域 add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; # 文件服务器根目录 root /home/public/hart_file; #是否可以访问目录下内容 autoindex on; # 是否展示真实文件大小 on:展示真实大小bytes autoindex_exact_size off; #是否展示文件时间为GMT时间 on : 文件服务器时间 autoindex_localtime on; add_header Cache-Control "no-cache, must-revalidate"; }}
阅读全文
0 0
- Nginx干货(二)配置详解
- Nginx配置详解 二!
- nginx配置干货
- Nginx配置文件(nginx.conf)配置详解(二)
- Nginx配置文件(nginx.conf)配置详解(二)
- JDBC 详解(干货分享)(二)
- 2016 Android 动画 详解 干货(二)
- nginx配置(二)
- Nginx配置文件(nginx.conf)配置详解
- Nginx配置文件(nginx.conf)配置详解
- Nginx配置文件(nginx.conf)配置详解
- nginx配置文件(nginx.conf)配置详解
- Nginx配置文件(nginx.conf)配置详解
- Nginx配置文件(nginx.conf)配置详解
- Nginx配置文件(nginx.conf)配置详解
- Nginx配置文件(nginx.conf)配置详解
- Nginx配置文件(nginx.conf)配置详解
- Nginx配置文件(nginx.conf)配置详解
- Druid 介绍及配置
- spring AspectJ的Execution表达式
- 黄成佳|企业家精神到底为何物?
- 社交复兴! 社交附能的知识付费平台更值得加码
- 执行分布式检索过程
- Nginx干货(二)配置详解
- 反射/jvm:newInstance 和 new
- Manipulator Jacobian
- Cognos BI
- 微服务架构初识
- 141. Linked List Cycle
- wxWidgets学习
- Android studio登录注册图形随机验证码
- CentOS 7 安装 LNMP 环境(PHP7 + MySQL5.7 + Nginx1.10)