侧边栏壁纸
博主头像
听听慢时光博主等级

行动起来,活在当下

  • 累计撰写 19 篇文章
  • 累计创建 25 个标签
  • 累计收到 7 条评论

目 录CONTENT

文章目录

你需要了解的Nginx有关配置

李开开
2024-04-11 / 0 评论 / 0 点赞 / 57 阅读 / 2604 字
温馨提示:
开卷有益,如果文章对您有所帮助,就点个大大的赞吧~
广告 广告

你需要了解的Nginx有关配置

人生海海,再相遇的几率小之又小,所以才应该时刻珍惜。——沧海一粟

环境

环境

Linux, Nginx, WSGI, WEB SERVER

Nginx的配置说明

user  root;
worker_processes  8;
worker_rlimit_nofile 65535;  # 为nginx工作进程打开最多文件数目的限制。

error_log  /data/logs/nginx/error.log;

pid /data/logs/nginx/nginx.pid;

events {
    worker_connections  20000; # 每一个worker进程能并发处理(发起)的最大连接数(包含所有连接数)。
}

http {
    include       mime.types; # 支持请求文件后缀
    default_type  application/octet-stream; # 默认文件类型,默认为text/plain

    log_format  log1  '[$time_local] $remote_addr $host $upstream_addr $request_uri $status $bytes_sent $upstream_response_time $request_time "$http_x_forwarded_for"'; # log 格式
    # log_format log2  '[$time_local] $remote_addr $host $upstream_addr $request_uri $status $bytes_sent $upstream_response_time $request_time "$http_x_forwarded_for" $cookie_id $cookie_ver $request_method $http_referer $http_user_agent $request_body ';

    access_log  /data/logs/nginx/access.log  log1; # 记录请求日志
    # access_log   off;

    sendfile        on;  # 开启高效传输模式  
    # tcp_nopush     on; # 当包累计到一定大小后发送,和 tcp_nodelay "互斥"。
    # tcp_nodelay     on; # 使缓冲区中的数据立即发送出去

    #keepalive_timeout  0; 
    #keepalive_timeout  65; # 在一段时间内保持打开状态,会在这段时间内占用资源。占用过多就会影响性能。

    gzip  on; # 开启gzip
    gzip_proxied      expired no-cache no-store private auth;
    gzip_disable      "MSIE [1-6] \."; # 配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
    gzip_http_version 1.0; 

    # include upstream.cfg; # cfg及config缩写,包含的负载均衡子配置文件
    # include server.cfg;

    include conf.d/upstream.conf;

     server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

}

子配置文件

conf.d/upstream.conf;

server {
      listen       8090; # 端口
      server_name  localhost; # domain
      #charset koi8-r;
      #access_log  logs/host.access.log  main;

      location / {
          root   html; # 文件根目录
          index  index.html index.htm; # 默认起始页
          }
     }

Nginx的特点

  • http协议代理:代理http协议,去访问ftp服务器。
  • 服务的反向代理
  • 在反向代理中配置集群的负载均衡
0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区