nginx内核优化及配置

简介:

1、内核优化

net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 30000
net.core.somaxconn = 262144
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 0
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_keepalive_intvl = 15
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_orphans = 262144
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.ip_conntrack_max = 6553600
net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 180
net.ipv4.tcp_window_scaling = 1
net.ipv4.ip_local_port_range = 1024    65000
net.ipv4.tcp_timestamps = 0


2、设置文件描述符

请参照http://linux008.blog.51cto.com/2837805/547654

3、nginx优化配置

user  www www;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
error_log  /usr/local/nginx/logs/error.log  warn;
worker_rlimit_nofile 65536;

events
{
      use epoll;
      worker_connections 65536;
}

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

        server_names_hash_bucket_size 128;

        keepalive_timeout 60;
        client_header_buffer_size    4k;   //系统分页大小#getconf PAGESIZE
        client_max_body_size         32m;
        large_client_header_buffers  8 1024k;
        client_header_timeout  3m;
        client_body_timeout    3m;
        send_timeout           3m;
        connection_pool_size        256;
        request_pool_size        4k;
        output_buffers   16 128k;
        postpone_output  1460;
        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 16 256k;
        fastcgi_busy_buffers_size 512k;
        fastcgi_temp_file_write_size 512k;
        fastcgi_temp_path /dev/shm;

        open_file_cache max=65536 inactive=20s;
        open_file_cache_min_uses 1;
        open_file_cache_valid 30s;


        tcp_nodelay on;
        gzip on;
        gzip_static on;
        gzip_proxied        any;
        gzip_disable        "MSIE [1-5]."
        gzip_comp_level     9;
        gzip_min_length  1k;
        gzip_buffers     16 128k;
        gzip_http_version 1.0;
        gzip_types       text/plain application/x-javascript text/css application/xml;
        server_name_in_redirect off;
        log_format  access  'remoteaddrremote_user - [timelocal]"request" '
                            'statusbody_bytes_sent "httpreferer""http_user_agent" $http_x_forwarded_for';
        include /usr/local/nginx/conf/vhost/*.conf;
}

4、vhost配置

   #vim /usr/local/nginx/conf/vhost/a.conf
   server
   {
    listen 80;
    server_name www.abc.com;
    root /data/httpd/csm.shopex.cn;
    index index.php index.html index.htm;
    location ~ .*\.php?$
    {
            include fastcgi.conf;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
    }
    #access_log  /var/log/nginx/nginx-access.log access;
    }

 

爱慕尔商城欢迎您的光临!
穿衣打扮  
城市物语



    本文转自yuangang_love 51CTO博客,原文链接:http://blog.51cto.com/linux008/594403,如需转载请自行联系原作者




目录
打赏
0
0
0
0
348
分享
相关文章
Nginx进程配置指令详解
Nginx进程配置指令主要包括:`worker_processes`设置工作进程数;`worker_cpu_affinity`绑定CPU核心;`worker_rlimit_nofile`设置最大文件描述符数量;`worker_priority`设置进程优先级;`worker_connections`设置最大连接数;`daemon`控制守护进程模式;`master_process`启用主进程模式;`pid`设置PID文件路径;`user`指定用户和组;`error_log`配置错误日志。这些指令在`nginx.conf`中配置,用于优化和控制Nginx的运行行为。
49 10
nginx配置证书和私钥进行SSL通信验证
nginx配置证书和私钥进行SSL通信验证
97 4
配置Nginx反向代理时如何指定后端服务器的权重?
配置Nginx反向代理时如何指定后端服务器的权重?
289 61
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
如何测试Nginx反向代理实现SSL加密访问的配置是否正确?
305 60
配置Nginx反向代理实现SSL加密访问的步骤是什么?
我们可以成功地配置 Nginx 反向代理实现 SSL 加密访问,为用户提供更安全、可靠的网络服务。同时,在实际应用中,还需要根据具体情况进行进一步的优化和调整,以满足不同的需求。SSL 加密是网络安全的重要保障,合理配置和维护是确保系统安全稳定运行的关键。
395 60
nginx反向代理bucket目录配置
该配置实现通过Nginx代理访问阿里云OSS存储桶中的图片资源。当用户访问代理域名下的图片URL(如 `http://代理域名/123.png`)时,Nginx会将请求转发到指定的OSS存储桶地址,并重写路径为 `/prod/files/2024/12/12/123.png`。
163 5
如何配置Nginx反向代理以实现负载均衡?
如何配置Nginx反向代理以实现负载均衡?
负载均衡指南:Nginx与HAProxy的配置与优化
负载均衡指南:Nginx与HAProxy的配置与优化
263 3
轻松上手Nginx Proxy Manager:安装、配置与实战
Nginx Proxy Manager (NPM) 是一款基于 Nginx 的反向代理管理工具,提供直观的 Web 界面,方便用户配置和管理反向代理、SSL 证书等。本文档介绍了 NPM 的安装步骤,包括 Docker 和 Docker Compose 的安装、Docker Compose 文件的创建与配置、启动服务、访问 Web 管理界面、基本使用方法以及如何申请和配置 SSL 证书,帮助用户快速上手 NPM。
1847 1
Nginx中配置HTTP2协议的方法
Nginx中配置HTTP2协议的方法
294 7