nginx 配置文件
| |
| [root@nginx_1 conf] |
| user root |
| worker_processes 4 |
| error_log logs/error.log |
| pid sbin/nginx.pid |
| |
| events { |
| use epoll |
| worker_connections 65535 |
| multi_accept on |
| } |
| |
| stream { |
| upstream cmp { |
| server 192.168.27.38:8080 max_fails=1 fail_timeout=10s |
| server 192.168.27.39:8080 max_fails=1 fail_timeout=10s backup |
| } |
| |
| server { |
| listen 22222 |
| proxy_pass cmp |
| } |
| |
| } |
| |
| http { |
| include mime.types |
| default_type application/octet-stream |
| types { |
| application/pdf |
| } |
| log_format main '$remote_addr - $remote_user [$time_local] "$request" ' |
| '$status $body_bytes_sent "$http_referer" ' |
| '"$http_user_agent" "$http_x_forwarded_for" "$upstream_addr"' |
| access_log logs/access.log main |
| sendfile on |
| keepalive_timeout 65 |
| fastcgi_buffers 8 128k |
| proxy_connect_timeout 1000 |
| proxy_send_timeout 1000 |
| proxy_read_timeout 1000 |
| fastcgi_connect_timeout 300 |
| fastcgi_send_timeout 300 |
| fastcgi_read_timeout 300 |
| client_max_body_size 200m |
| server_tokens off |
| include vhosts/local_upstream.conf |
| include vhosts/server.conf |
| proxy_buffering on |
| proxy_buffer_size 256k |
| proxy_buffers 64 256K |
| proxy_busy_buffers_size 512k |
| proxy_temp_file_write_size 512k |
| proxy_temp_path /tmp/temp_buffer |
| |
| |
| |
| gzip on |
| |
| gzip_types text/plain application/javascript text/css application/xml text/javascript image/jpeg image/gif image/png |
| |
| gzip_comp_level 5 |
| |
| gzip_vary on |
| |
| gzip_buffers 16 8k |
| |
| gzip_disable "MSIE [1-6]\." |
| |
| gzip_http_version 1.1 |
| |
| gzip_min_length 10k |
| |
| gzip_proxied off |
| } |
| |
| |
| [root@nginx_1 conf] |
| server{ |
| listen 8099 |
| server_name mirrors.aliyun.com |
| location ~ ^/*{ |
| proxy_redirect off |
| proxy_set_header Host $host |
| proxy_set_header X-Forwarded-Host $host |
| proxy_set_header X-Forwarded-Server $host |
| proxy_set_header X-Real-IP $remote_addr |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for |
| proxy_buffering off |
| chunked_transfer_encoding off |
| proxy_pass http://mirrors.aliyun.com |
| client_max_body_size 512m |
| } |
| } |
| |
| server { |
| listen 443 ssl http2 |
| ssl_certificate /home/nginx/conf/crt/9371738__test.com.pem |
| ssl_certificate_key /home/nginx/conf/crt/9371738__test.com.key |
| |
| ssl_session_cache shared:SSL:1m |
| ssl_session_timeout 5m |
| ssl_protocols TLSv1 TLSv1.1 TLSv1.2 |
| |
| ssl_ciphers ECDHE-RSA-AES256-SHA384:AES256-SHA256:RC4:HIGH:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!AESGCM |
| ssl_prefer_server_ciphers on |
| |
| proxy_read_timeout 3600s |
| proxy_http_version 1.1 |
| proxy_set_header Upgrade $http_upgrade |
| proxy_set_header Connection "upgrade" |
| |
| server_name cloud.test.com |
| include vhosts/local.conf |
| |
| if ($host !~* "^[a-zA-Z0-9_]{3,10}\.test.com$") { |
| return 444 |
| } |
| error_page 404 /error.html |
| error_page 500 502 503 504 /error.html |
| location = /error.html { |
| root html |
| } |
| |
| server { |
| listen 8010 default_server |
| server_name test.com |
| include vhosts/local.conf |
| error_page 404 /error.html |
| error_page 500 502 503 504 /error.html |
| location = /error.html { |
| root html |
| } |
| } |
| |
| |
| [root@nginx_1 vhosts] |
| location /ws/ { |
| proxy_pass http://ws |
| proxy_redirect off |
| 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_http_version 1.1 |
| proxy_set_header Upgrade $http_upgrade |
| proxy_set_header Connection "upgrade" |
| } |
| |
| location /test_api/ { |
| proxy_pass http://test_api |
| proxy_redirect off |
| proxy_set_header Host $host |
| proxy_set_header X-Real-IP $remote_addr |
| } |
| |
| location /test_api2{ |
| proxy_pass http://test_api2 |
| proxy_redirect http:// https:// |
| proxy_set_header Host $host:1443 |
| proxy_connect_timeout 90 |
| proxy_send_timeout 90 |
| proxy_read_timeout 90 |
| proxy_buffer_size 4k |
| proxy_buffers 32 4k |
| proxy_busy_buffers_size 64k |
| |
| add_header Access-Control-Allow-Origin $http_origin |
| add_header X-Content-Type-Options "nosniff" |
| add_header X-XSS-Protection "1" |
| add_header Set-Cookie "HttpOnly" |
| add_header Set-Cookie "Secure" |
| add_header X-Frame-Options SAMEORIGIN |
| add_header Content-Security-Policy "default-src * |
| add_header 'Access-Control-Allow-Methods' "POST, GET" |
| } |
| |
| |
| [root@nginx_1 vhosts] |
| upstream gls{ |
| sticky |
| server 192.168.1.2:8080 |
| server 192.168.1.3:8080 |
| check interval=3000 rise=3 fall=5 timeout=1000 type=tcp |
| } |
nginx配置文件优化
- worker_processes nginx进程工作数
| #cat /proc/cpuinfo |grep processor|wc -l ,或者是设置auto自动根据CPU 核心数来确定 worker 进程的数量都行。 |
| worker_processes auto; |
| worker_processes 2; |
| events { |
| |
| use epoll |
| |
| worker_connections 65535 |
| |
| multi_accept on |
| } |
| sendfile on |
| |
| tcp_nodelay on |
| |
| keepalive_timeout 65 |
| |
| open_file_cache max=204800 inactive=20s |
| |
| open_file_cache_valid 30s |
| |
| open_file_cache_min_uses 1 |
| |
| client_header_buffer_size 4k |
| |
| |
| |
| |
| fastcgi_buffers 8 128k |
| |
| proxy_connect_timeout 600s |
| |
| proxy_send_timeout 600s |
| 设置代理读取超时时间为600秒。 |
| proxy_read_timeout 600s |
| fastcgi_connect_timeout 300s |
| fastcgi_send_timeout 300s |
| fastcgi_read_timeout 300s |
| |
| client_max_body_size 200m |
| |
| server_tokens off |
| include vhosts/local_upstream.conf |
| include vhosts/server.conf |
| |
| proxy_buffering on |
| |
| proxy_buffer_size 256k |
| |
| proxy_buffers 64 256K |
| |
| proxy_busy_buffers_size 512k |
| |
| proxy_temp_file_write_size 512k |
| |
| proxy_temp_path /tmp/temp_buffer |
| |
| location ~* \.(jpg|jpeg|png|gif|ico|swf|flv|bmp)$ |
| expires 30d |
| access_log off |
| |
| location ~* \.(js|css)$ |
| expires 7d |
| access_log off |
| location ~* \.(jpg|jpeg|png|gif|ico|swf|flv|bmp|zip|mp3|mp4|)$ { |
| valid_referers none blocked www.test.com *.test123.com; |
| if ($invalid_referer) { |
| return 403; |
| } |
| } |
nginx服务器内核优化
| |
| fs.file-max = 999999 |
| |
| net.ipv4.tcp_tw_reuse = 1 |
| |
| net.ipv4.tcp_keepalive_time = 15 |
| |
| net.ipv4.tcp_fin_timeout = 15 |
| |
| net.ipv4.tcp_max_tw_buckets = 5000 |
| |
| net.ipv4.ip_local_port_range = 1024 65000 |
| |
| net.ipv4.tcp_rmem = 4096 32768 262144 |
| |
| net.ipv4.tcp_wmem = 4096 32768 262144 |
| |
| net.ipv4.tcp_max_orphans = 262144 |
| |
| net.core.netdev_max_backlog = 262144 |
| |
| net.core.rmem_default = 262144 |
| |
| net.core.wmem_default = 262144 |
| |
| net.core.rmem_max = 2097152 |
| |
| net.core.wmem_max = 2097152 |
| |
| net.core.somaxconn = 262144 |
| |
| net.ipv4.tcp_syncookies = 1 |
| |
| net.ipv4.tcp_max_syn_backlog=262144 |
本文由mdnice多平台发布
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构