美文网首页
Nginx代理调优

Nginx代理调优

作者: liurongming | 来源:发表于2021-09-08 15:41 被阅读0次
  • 优化参数
    proxy_set_header X-Real-IP $remote_addr;
     proxy_set_header Host $host;
     proxy_pass http://127.0.0.1:8080 ;

     client_max_body_size  100m;
     client_body_buffer_size 256k;
     proxy_connect_timeout 1200;
     proxy_read_timeout  1200;
     proxy_send_timeout  6000;
     proxy_buffer_size  32k;
     proxy_buffers   4 64k;
     proxy_busy_buffers_size 128k;
     proxy_temp_file_write_size 10m;

proxy_connect_timeout 600; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_read_timeout 600; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_send_timeout 600; #后端服务器数据回传时间(代理发送超时)
proxy_buffer_size 32k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 10m; #设定缓存文件夹大小,大于这个值,将从upstream服务器传

  • 单个配置:
location /api {
         # 传递真实的请求头信息
         proxy_set_header Host $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         # 限制文件大小为1G
         client_max_body_size    10240m;

         # 允许跨域
         add_header Access-Control-Allow-Origin *;
         add_header Access-Control-Allow-Headers X-Requested-With;
         add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

         # 调优
         client_body_buffer_size 256k;
         proxy_connect_timeout 1200;
         proxy_read_timeout  1200;
         proxy_send_timeout  6000;
         proxy_buffer_size  32k;
         proxy_buffers   4 64k;
         proxy_busy_buffers_size 128k;
         proxy_temp_file_write_size 10m;

         rewrite ^.+api/?(.*)$ /$1 break;
         include uwsgi_params;
         proxy_pass http://172.18.5.175:9999;
    }
  • 全局配置
[root@itdev9902 nginx]# cat nginx.conf
user  nginx;
worker_processes  auto;

error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;
    ## 全局允许跨域
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Headers X-Requested-With;
    add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

     # 调优
    client_max_body_size    10240m;
    client_body_buffer_size 256k;
    proxy_connect_timeout 1200;
    proxy_read_timeout  1200;
    proxy_send_timeout  6000;
    proxy_buffer_size  32k;
    proxy_buffers   4 64k;
    proxy_busy_buffers_size 128k;
    proxy_temp_file_write_size 10m;

    include /etc/nginx/conf.d/*.conf;
}

常用配置

server {
        listen  80;
        server_name minio.punan.xyz;
        rewrite ^(.*)$  https://$host$1 permanent;
}

server {
        listen  443 ssl;
        server_name  minio.xxx.xyz;
        #access_log /var/log/nginx/pro.log;

        #ssl on;
        #SSL-START SSL
        ssl_certificate certs/minio/minio.punan.xyz_bundle.crt;
        ssl_certificate_key certs/minio/minio.punan.xyz.key;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
        ssl_session_timeout 15m;
        #SSL-END


        location  / {
                # 传递真实的请求头信息
                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://172.16.16.9:9000;

                proxy_http_version  1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";

                ## 允许跨域
                add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Headers X-Requested-With;
                add_header Access-Control-Allow-Methods GET,POST,OPTIONS;

                # 调优
                client_max_body_size    10240m;
                client_body_buffer_size 256k;
                proxy_connect_timeout 900;
                proxy_read_timeout  900;
                proxy_send_timeout  900;
                proxy_buffer_size  32k;
                proxy_buffers   4 64k;
                proxy_busy_buffers_size 128k;
                proxy_temp_file_write_size 10m;
        }

        error_page 500 502 503 504  /50x.html;
        location = /50x.html {
                root   /usr/share/nginx/html;
        }
}

相关文章

  • Nginx代理调优

    优化参数 proxy_connect_timeout 600; #nginx跟后端服务器连接超时时间(代理连接超时...

  • Nginx负载调优总结

    nginx负载调优总结 一、调优手册 二、参数获取方式及调优详解: 对nginx的调优很大一部分是对nginx配置...

  • 【转】Nginx 配置和性能调优

    Nginx 配置和性能调优

  • Nginx 核心配置

    2.1Nginx 性能调优 ​ 在 Nginx 性能调优中,有两个非常重要的理论点(面试点)需要掌握。...

  • nginx调优

    1.首先添加rlimit 2.进程数修改 3.access日志关掉 user nobody; worker_pr...

  • Nginx 调优

    博客引流 环境: Ubuntu18.04.1 LTS - aliYunnginx/1.15.3openssl 1....

  • nginx调优

    转载别人的文章,nginx调优。链接如下:http://blog.csdn.net/xifeijian/artic...

  • Nginx调优

    下文涉及到的相关模块的安装,请参见Nginx源码安装 1. worker_processes 建议配置 测试OS:...

  • 日更第3日: (翻)nginx调优之worker调优

    worker调优 原文地址[https://github.com/trimstray/nginx-admins-h...

  • Nginx参数调优

    Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-...

网友评论

      本文标题:Nginx代理调优

      本文链接:https://www.haomeiwen.com/subject/eupvwltx.html