G
N
I
D
A
O
L
W
e
l
c
o
m
e
: )

nginx配置文件

user www www;

#指定nginx用户

worker_processes 8;

#nginx可以创建的工作进程

worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

指定nginx的cpu

pid /usr/local/nginx/nginx.pid;

#指定nginx的pid文件

worker_rlimit_nofile 102400;

#nginx线程可以打开的文件描述符

events

{

use epoll;

#启用epll模型

worker_connections 102400;

#单个后台worker process进程的最大并发链接数(最大连接数=连接数*进程数)

}

multi_accept  on;

#尽可能多的接受请求.

http

{

  include       mime.types;

 #设定mime类型,类型由mime.type文件定义

  default_type  application/octet-stream;

FastCGI_intercept_errors on;

#这个指令指定是否传递4xx和5xx错误信息到客户端,或者允许nginx使用error_page处理错误信息

  charset  utf-8;

#设置字符集

  server_names_hash_bucket_size 128;

#设置域名的大小

  client_header_buffer_size 4k;

#缓冲区代理缓冲用户端请求的最大字节数.

  large_client_header_buffers 4 32k;

#设定请求头缓冲

  client_max_body_size 300m;

#客户端请求头最大值

  sendfile on;

#开启高效文件传输模式

  tcp_nopush     on;

  keepalive_timeout 60;

#客户端连接超时时间

  tcp_nodelay on;

#提高数据的实时响应性

  client_body_buffer_size  2k;

#客户端请求头部的缓冲区大小,这个可以根据你的系统分页大小来设置,一般一个请求的头部大小不会超过1k

  proxy_connect_timeout    5;

#指定了后端服务器的连接超时时间

  proxy_read_timeout       60;

#连接成功后,后端服务器的响应时间

  proxy_send_timeout       5;

#后端服务器数据回传时间

  proxy_buffer_size        16k;

#设置代理服务器(nginx)保存用户头信息的缓冲区大小

  proxy_buffers            4 64k;

#proxy_buffers缓冲区,网页平均在32k以下的话,这样设置

  proxy_busy_buffers_size 128k;

#高负荷下缓冲大小(proxy_buffers*2)

  proxy_temp_file_write_size 128k;

open_file_cache_valid 30s;

#这个是指多长时间检查一次缓存的有效信息。

  gzip on;

#开启压缩

  gzip_min_length  1k;

#设置允许压缩的页面最小字节数,页面字节数从header头中的Content-Length中进行获取

  gzip_buffers     4 16k;

#设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流。 例如 4 4k 代表以4k为单位,按照原始数据大小以4k为单位的4倍申请内存。

  gzip_http_version 1.1;

#识别http版本

  gzip_comp_level 2;

#指定了压缩的级别1到9 (1级别最低,9级别最高压缩的级别高对资源占用越大)

  gzip_types       text/plain application/x-javascript text/css application/xml;

#指定了压缩的文件类型

  gzip_vary on;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

              '$status $body_bytes_sent "$http_referer" '

              '"$http_user_agent"  $request_time';

#定义了日志中的变量

upstream  jvm_web1 {

    server   192.168.149.130:8080  weight=1  max_fails=2  fail_timeout=30s;

    server   192.168.149.130:8081  weight=1  max_fails=2  fail_timeout=30s;

}

#负载均衡模块weight(权重),max_fail(失败后从连几次),fail_timeout()

include vhosts.conf/*。conf;

#定义了读取虚拟主机的位置

}

 

#虚拟主机配置

    server {

       #侦听80端口

        listen       80;

        #定义使用www.jfedu.net访问

        server_name  www.jfedu.net;

        #设定本虚拟主机的访问日志

        access_log  logs/access.log  main;

       root   /data/webapps/www;  #定义服务器的默认网站根目录位置

        index index.php index.html index.htm;   #定义首页索引文件的名称

        #默认请求

        location ~ /{

          root   /data/webapps/www;      #定义服务器的默认网站根目录位置

          index index.php index.html index.htm;   #定义首页索引文件的名称

          #以下是一些反向代理的配置.

         proxy_next_upstream http_502 http_504 error timeout invalid_header;

         #如果后端的服务器返回502、504、执行超时等错误,自动将请求转发到upstream负载均衡池中的另一台服务器,实现故障转移。

          proxy_redirect off;

          #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP

          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://jfedu_www;     #请求转向后端定义的均衡模块

       }

        # 定义错误提示页面

           error_page   500 502 503 504 /50x.html; 

            location = /50x.html {

            root   html;

        }

       #配置Nginx动静分离,定义的静态页面直接从Nginx发布目录读取。

       location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$

       {

           root /data/webapps/www;

           #expires定义用户浏览器缓存的时间为3天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力,在浏览器保存该类型文件的天数。

           expires      3d

       }

        #PHP脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.

        location ~ \.php$ {

            root /root;

            FastCGI_pass 127.0.0.1:9000;

            FastCGI_index index.php;

            FastCGI_param SCRIPT_FILENAME /data/webapps/www$FastCGI_script_name;

            include FastCGI_params;

        }

        #设定查看Nginx状态的地址

        location /NginxStatus {

            stub_status  on;

        }

     }

}

posted @ 2019-10-02 22:43  狸猫大侠  阅读(82)  评论(0编辑  收藏  举报