[{"data":1,"prerenderedAt":1939},["ShallowReactive",2],{"\u002Foptimize\u002Fflask-nginx-performance-tuning-guide":3},{"id":4,"title":5,"body":6,"description":1929,"extension":1930,"meta":1931,"navigation":89,"path":1935,"seo":1936,"stem":1937,"__hash__":1938},"content\u002Foptimize\u002Fflask-nginx-performance-tuning-guide.md","Flask Nginx Performance Tuning Guide",{"type":7,"value":8,"toc":1904},"minimark",[9,13,17,22,25,218,225,229,232,235,238,242,247,250,278,281,302,306,313,352,355,381,385,392,446,449,480,484,489,514,517,521,525,600,603,623,627,630,633,729,736,745,749,752,776,779,783,788,875,878,952,956,959,1124,1128,1131,1169,1172,1188,1192,1195,1218,1225,1229,1232,1299,1302,1319,1323,1326,1340,1352,1356,1408,1412,1415,1432,1435,1448,1451,1469,1472,1496,1499,1520,1523,1555,1558,1575,1578,1591,1594,1625,1628,1656,1659,1688,1691,1718,1729,1733,1816,1820,1840,1844,1854,1866,1874,1885,1893,1897,1900],[10,11,5],"h1",{"id":12},"flask-nginx-performance-tuning-guide",[14,15,16],"p",{},"If you're trying to improve Flask production performance behind Nginx, this guide shows you how to tune the reverse proxy step-by-step. It focuses on the Nginx settings that most directly affect throughput, keepalive behavior, buffering, compression, and static file delivery.",[18,19,21],"h2",{"id":20},"quick-fix-quick-setup","Quick Fix \u002F Quick Setup",[14,23,24],{},"Use this baseline if you need a fast starting point before deeper tuning.",[26,27,32],"pre",{"className":28,"code":29,"language":30,"meta":31,"style":31},"language-bash shiki shiki-themes github-light github-dark","sudo cp \u002Fetc\u002Fnginx\u002Fnginx.conf \u002Fetc\u002Fnginx\u002Fnginx.conf.bak\nsudo tee \u002Fetc\u002Fnginx\u002Fconf.d\u002Fflask-performance.conf > \u002Fdev\u002Fnull \u003C\u003C'EOF'\nworker_processes auto;\n\n# put inside http context if your distro uses includes under \u002Fetc\u002Fnginx\u002Fconf.d\u002F\nworker_rlimit_nofile 65535;\n\nevents {\n    worker_connections 4096;\n    multi_accept on;\n    use epoll;\n}\nEOF\n\nsudo awk '1; \u002Fhttp \\{\u002F && !x {print \"    sendfile on;\\n    tcp_nopush on;\\n    tcp_nodelay on;\\n    keepalive_timeout 15;\\n    keepalive_requests 1000;\\n    types_hash_max_size 2048;\\n    client_max_body_size 20M;\\n    server_tokens off;\\n    open_file_cache max=10000 inactive=30s;\\n    open_file_cache_valid 60s;\\n    open_file_cache_min_uses 2;\\n    open_file_cache_errors on;\\n    gzip on;\\n    gzip_comp_level 5;\\n    gzip_min_length 1024;\\n    gzip_vary on;\\n    gzip_proxied any;\\n    gzip_types text\u002Fplain text\u002Fcss text\u002Fxml application\u002Fjson application\u002Fjavascript application\u002Fxml+rss application\u002Fxml image\u002Fsvg+xml;\"; x=1 }' \u002Fetc\u002Fnginx\u002Fnginx.conf | sudo tee \u002Fetc\u002Fnginx\u002Fnginx.conf.new > \u002Fdev\u002Fnull\nsudo mv \u002Fetc\u002Fnginx\u002Fnginx.conf.new \u002Fetc\u002Fnginx\u002Fnginx.conf\nsudo nginx -t && sudo systemctl reload nginx\n","bash","",[33,34,35,54,78,84,91,97,103,108,114,120,126,132,138,144,149,178,191],"code",{"__ignoreMap":31},[36,37,40,44,48,51],"span",{"class":38,"line":39},"line",1,[36,41,43],{"class":42},"sScJk","sudo",[36,45,47],{"class":46},"sZZnC"," cp",[36,49,50],{"class":46}," \u002Fetc\u002Fnginx\u002Fnginx.conf",[36,52,53],{"class":46}," \u002Fetc\u002Fnginx\u002Fnginx.conf.bak\n",[36,55,57,59,62,65,69,72,75],{"class":38,"line":56},2,[36,58,43],{"class":42},[36,60,61],{"class":46}," tee",[36,63,64],{"class":46}," \u002Fetc\u002Fnginx\u002Fconf.d\u002Fflask-performance.conf",[36,66,68],{"class":67},"szBVR"," >",[36,70,71],{"class":46}," \u002Fdev\u002Fnull",[36,73,74],{"class":67}," \u003C\u003C",[36,76,77],{"class":46},"'EOF'\n",[36,79,81],{"class":38,"line":80},3,[36,82,83],{"class":46},"worker_processes auto;\n",[36,85,87],{"class":38,"line":86},4,[36,88,90],{"emptyLinePlaceholder":89},true,"\n",[36,92,94],{"class":38,"line":93},5,[36,95,96],{"class":46},"# put inside http context if your distro uses includes under \u002Fetc\u002Fnginx\u002Fconf.d\u002F\n",[36,98,100],{"class":38,"line":99},6,[36,101,102],{"class":46},"worker_rlimit_nofile 65535;\n",[36,104,106],{"class":38,"line":105},7,[36,107,90],{"emptyLinePlaceholder":89},[36,109,111],{"class":38,"line":110},8,[36,112,113],{"class":46},"events {\n",[36,115,117],{"class":38,"line":116},9,[36,118,119],{"class":46},"    worker_connections 4096;\n",[36,121,123],{"class":38,"line":122},10,[36,124,125],{"class":46},"    multi_accept on;\n",[36,127,129],{"class":38,"line":128},11,[36,130,131],{"class":46},"    use epoll;\n",[36,133,135],{"class":38,"line":134},12,[36,136,137],{"class":46},"}\n",[36,139,141],{"class":38,"line":140},13,[36,142,143],{"class":46},"EOF\n",[36,145,147],{"class":38,"line":146},14,[36,148,90],{"emptyLinePlaceholder":89},[36,150,152,154,157,160,162,165,168,170,173,175],{"class":38,"line":151},15,[36,153,43],{"class":42},[36,155,156],{"class":46}," awk",[36,158,159],{"class":46}," '1; \u002Fhttp \\{\u002F && !x {print \"    sendfile on;\\n    tcp_nopush on;\\n    tcp_nodelay on;\\n    keepalive_timeout 15;\\n    keepalive_requests 1000;\\n    types_hash_max_size 2048;\\n    client_max_body_size 20M;\\n    server_tokens off;\\n    open_file_cache max=10000 inactive=30s;\\n    open_file_cache_valid 60s;\\n    open_file_cache_min_uses 2;\\n    open_file_cache_errors on;\\n    gzip on;\\n    gzip_comp_level 5;\\n    gzip_min_length 1024;\\n    gzip_vary on;\\n    gzip_proxied any;\\n    gzip_types text\u002Fplain text\u002Fcss text\u002Fxml application\u002Fjson application\u002Fjavascript application\u002Fxml+rss application\u002Fxml image\u002Fsvg+xml;\"; x=1 }'",[36,161,50],{"class":46},[36,163,164],{"class":67}," |",[36,166,167],{"class":42}," sudo",[36,169,61],{"class":46},[36,171,172],{"class":46}," \u002Fetc\u002Fnginx\u002Fnginx.conf.new",[36,174,68],{"class":67},[36,176,177],{"class":46}," \u002Fdev\u002Fnull\n",[36,179,181,183,186,188],{"class":38,"line":180},16,[36,182,43],{"class":42},[36,184,185],{"class":46}," mv",[36,187,172],{"class":46},[36,189,190],{"class":46}," \u002Fetc\u002Fnginx\u002Fnginx.conf\n",[36,192,194,196,199,203,207,209,212,215],{"class":38,"line":193},17,[36,195,43],{"class":42},[36,197,198],{"class":46}," nginx",[36,200,202],{"class":201},"sj4cs"," -t",[36,204,206],{"class":205},"sVt8B"," && ",[36,208,43],{"class":42},[36,210,211],{"class":46}," systemctl",[36,213,214],{"class":46}," reload",[36,216,217],{"class":46}," nginx\n",[14,219,220,221,224],{},"Use this as a baseline only. Confirm your distro layout before editing ",[33,222,223],{},"nginx.conf",". Keep upstream proxy settings and static file locations in the site config.",[18,226,228],{"id":227},"whats-happening","What’s Happening",[14,230,231],{},"Nginx performance issues usually come from inefficient worker settings, poor keepalive behavior, missing compression, excessive disk I\u002FO, or sending static files through Gunicorn instead of Nginx.",[14,233,234],{},"For Flask apps, Nginx should terminate client connections, cache file metadata, compress text assets, and proxy dynamic requests efficiently to Gunicorn.",[14,236,237],{},"The goal is to reduce request overhead at the edge so Gunicorn handles only application work.",[18,239,241],{"id":240},"step-by-step-guide","Step-by-Step Guide",[243,244,246],"h3",{"id":245},"_1-validate-the-current-nginx-configuration","1. Validate the current Nginx configuration",[14,248,249],{},"Check syntax and print the full active configuration.",[26,251,253],{"className":28,"code":252,"language":30,"meta":31,"style":31},"sudo nginx -t\nsudo nginx -T | less\n",[33,254,255,264],{"__ignoreMap":31},[36,256,257,259,261],{"class":38,"line":39},[36,258,43],{"class":42},[36,260,198],{"class":46},[36,262,263],{"class":201}," -t\n",[36,265,266,268,270,273,275],{"class":38,"line":56},[36,267,43],{"class":42},[36,269,198],{"class":46},[36,271,272],{"class":201}," -T",[36,274,164],{"class":67},[36,276,277],{"class":42}," less\n",[14,279,280],{},"Confirm:",[282,283,284,288,295],"ul",{},[285,286,287],"li",{},"the expected server block is loaded",[285,289,290,291,294],{},"the expected ",[33,292,293],{},"include"," files are present",[285,296,297,298,301],{},"static file ",[33,299,300],{},"location"," blocks are not missing",[243,303,305],{"id":304},"_2-set-worker-capacity-in-the-main-config","2. Set worker capacity in the main config",[14,307,308,309,312],{},"Edit ",[33,310,311],{},"\u002Fetc\u002Fnginx\u002Fnginx.conf",":",[26,314,318],{"className":315,"code":316,"language":317,"meta":31,"style":31},"language-nginx shiki shiki-themes github-light github-dark","worker_processes auto;\nworker_rlimit_nofile 65535;\n\nevents {\n    worker_connections 4096;\n    multi_accept on;\n    use epoll;\n}\n","nginx",[33,319,320,324,328,332,336,340,344,348],{"__ignoreMap":31},[36,321,322],{"class":38,"line":39},[36,323,83],{},[36,325,326],{"class":38,"line":56},[36,327,102],{},[36,329,330],{"class":38,"line":80},[36,331,90],{"emptyLinePlaceholder":89},[36,333,334],{"class":38,"line":86},[36,335,113],{},[36,337,338],{"class":38,"line":93},[36,339,119],{},[36,341,342],{"class":38,"line":99},[36,343,125],{},[36,345,346],{"class":38,"line":105},[36,347,131],{},[36,349,350],{"class":38,"line":110},[36,351,137],{},[14,353,354],{},"Notes:",[282,356,357,363,369,375],{},[285,358,359,362],{},[33,360,361],{},"worker_processes auto;"," matches CPU count",[285,364,365,368],{},[33,366,367],{},"worker_connections"," affects concurrency capacity",[285,370,371,374],{},[33,372,373],{},"use epoll;"," is appropriate on Linux",[285,376,377,380],{},[33,378,379],{},"worker_rlimit_nofile"," must align with OS and systemd limits",[243,382,384],{"id":383},"_3-tune-core-http-behavior","3. Tune core HTTP behavior",[14,386,387,388,391],{},"Inside the ",[33,389,390],{},"http"," block, add or confirm:",[26,393,395],{"className":315,"code":394,"language":317,"meta":31,"style":31},"http {\n    sendfile on;\n    tcp_nopush on;\n    tcp_nodelay on;\n    keepalive_timeout 15;\n    keepalive_requests 1000;\n    types_hash_max_size 2048;\n    client_max_body_size 20M;\n    server_tokens off;\n}\n",[33,396,397,402,407,412,417,422,427,432,437,442],{"__ignoreMap":31},[36,398,399],{"class":38,"line":39},[36,400,401],{},"http {\n",[36,403,404],{"class":38,"line":56},[36,405,406],{},"    sendfile on;\n",[36,408,409],{"class":38,"line":80},[36,410,411],{},"    tcp_nopush on;\n",[36,413,414],{"class":38,"line":86},[36,415,416],{},"    tcp_nodelay on;\n",[36,418,419],{"class":38,"line":93},[36,420,421],{},"    keepalive_timeout 15;\n",[36,423,424],{"class":38,"line":99},[36,425,426],{},"    keepalive_requests 1000;\n",[36,428,429],{"class":38,"line":105},[36,430,431],{},"    types_hash_max_size 2048;\n",[36,433,434],{"class":38,"line":110},[36,435,436],{},"    client_max_body_size 20M;\n",[36,438,439],{"class":38,"line":116},[36,440,441],{},"    server_tokens off;\n",[36,443,444],{"class":38,"line":122},[36,445,137],{},[14,447,448],{},"Why:",[282,450,451,457,467,474],{},[285,452,453,456],{},[33,454,455],{},"sendfile"," improves static file transfer efficiency",[285,458,459,462,463,466],{},[33,460,461],{},"tcp_nopush"," and ",[33,464,465],{},"tcp_nodelay"," improve packet behavior",[285,468,469,470,473],{},"shorter ",[33,471,472],{},"keepalive_timeout"," reduces idle socket usage",[285,475,476,479],{},[33,477,478],{},"keepalive_requests"," allows connection reuse without holding sockets forever",[243,481,483],{"id":482},"_4-add-file-metadata-caching","4. Add file metadata caching",[14,485,387,486,488],{},[33,487,390],{}," block:",[26,490,492],{"className":315,"code":491,"language":317,"meta":31,"style":31},"open_file_cache max=10000 inactive=30s;\nopen_file_cache_valid 60s;\nopen_file_cache_min_uses 2;\nopen_file_cache_errors on;\n",[33,493,494,499,504,509],{"__ignoreMap":31},[36,495,496],{"class":38,"line":39},[36,497,498],{},"open_file_cache max=10000 inactive=30s;\n",[36,500,501],{"class":38,"line":56},[36,502,503],{},"open_file_cache_valid 60s;\n",[36,505,506],{"class":38,"line":80},[36,507,508],{},"open_file_cache_min_uses 2;\n",[36,510,511],{"class":38,"line":86},[36,512,513],{},"open_file_cache_errors on;\n",[14,515,516],{},"This reduces repeated file lookup overhead for static-heavy deployments.",[243,518,520],{"id":519},"_5-enable-gzip-compression-for-text-responses","5. Enable gzip compression for text responses",[14,522,387,523,488],{},[33,524,390],{},[26,526,528],{"className":315,"code":527,"language":317,"meta":31,"style":31},"gzip on;\ngzip_comp_level 5;\ngzip_min_length 1024;\ngzip_vary on;\ngzip_proxied any;\ngzip_types\n    text\u002Fplain\n    text\u002Fcss\n    text\u002Fxml\n    application\u002Fjson\n    application\u002Fjavascript\n    application\u002Fxml+rss\n    application\u002Fxml\n    image\u002Fsvg+xml;\n",[33,529,530,535,540,545,550,555,560,565,570,575,580,585,590,595],{"__ignoreMap":31},[36,531,532],{"class":38,"line":39},[36,533,534],{},"gzip on;\n",[36,536,537],{"class":38,"line":56},[36,538,539],{},"gzip_comp_level 5;\n",[36,541,542],{"class":38,"line":80},[36,543,544],{},"gzip_min_length 1024;\n",[36,546,547],{"class":38,"line":86},[36,548,549],{},"gzip_vary on;\n",[36,551,552],{"class":38,"line":93},[36,553,554],{},"gzip_proxied any;\n",[36,556,557],{"class":38,"line":99},[36,558,559],{},"gzip_types\n",[36,561,562],{"class":38,"line":105},[36,563,564],{},"    text\u002Fplain\n",[36,566,567],{"class":38,"line":110},[36,568,569],{},"    text\u002Fcss\n",[36,571,572],{"class":38,"line":116},[36,573,574],{},"    text\u002Fxml\n",[36,576,577],{"class":38,"line":122},[36,578,579],{},"    application\u002Fjson\n",[36,581,582],{"class":38,"line":128},[36,583,584],{},"    application\u002Fjavascript\n",[36,586,587],{"class":38,"line":134},[36,588,589],{},"    application\u002Fxml+rss\n",[36,591,592],{"class":38,"line":140},[36,593,594],{},"    application\u002Fxml\n",[36,596,597],{"class":38,"line":146},[36,598,599],{},"    image\u002Fsvg+xml;\n",[14,601,602],{},"This is usually worth enabling for:",[282,604,605,608,611,614,617,620],{},[285,606,607],{},"HTML",[285,609,610],{},"CSS",[285,612,613],{},"JavaScript",[285,615,616],{},"JSON APIs",[285,618,619],{},"XML",[285,621,622],{},"SVG",[243,624,626],{"id":625},"_6-serve-static-files-directly-from-nginx","6. Serve static files directly from Nginx",[14,628,629],{},"Do not send static files through Gunicorn.",[14,631,632],{},"Example server block:",[26,634,636],{"className":315,"code":635,"language":317,"meta":31,"style":31},"server {\n    listen 80;\n    server_name example.com;\n\n    location \u002Fstatic\u002F {\n        alias \u002Fsrv\u002Fmyapp\u002Fcurrent\u002Fapp\u002Fstatic\u002F;\n        expires 30d;\n        add_header Cache-Control \"public, immutable\";\n        access_log off;\n        log_not_found off;\n    }\n\n    location \u002Fmedia\u002F {\n        alias \u002Fsrv\u002Fmyapp\u002Fshared\u002Fmedia\u002F;\n        expires 7d;\n        access_log off;\n        log_not_found off;\n    }\n}\n",[33,637,638,643,648,653,657,662,667,672,677,682,687,692,696,701,706,711,715,719,724],{"__ignoreMap":31},[36,639,640],{"class":38,"line":39},[36,641,642],{},"server {\n",[36,644,645],{"class":38,"line":56},[36,646,647],{},"    listen 80;\n",[36,649,650],{"class":38,"line":80},[36,651,652],{},"    server_name example.com;\n",[36,654,655],{"class":38,"line":86},[36,656,90],{"emptyLinePlaceholder":89},[36,658,659],{"class":38,"line":93},[36,660,661],{},"    location \u002Fstatic\u002F {\n",[36,663,664],{"class":38,"line":99},[36,665,666],{},"        alias \u002Fsrv\u002Fmyapp\u002Fcurrent\u002Fapp\u002Fstatic\u002F;\n",[36,668,669],{"class":38,"line":105},[36,670,671],{},"        expires 30d;\n",[36,673,674],{"class":38,"line":110},[36,675,676],{},"        add_header Cache-Control \"public, immutable\";\n",[36,678,679],{"class":38,"line":116},[36,680,681],{},"        access_log off;\n",[36,683,684],{"class":38,"line":122},[36,685,686],{},"        log_not_found off;\n",[36,688,689],{"class":38,"line":128},[36,690,691],{},"    }\n",[36,693,694],{"class":38,"line":134},[36,695,90],{"emptyLinePlaceholder":89},[36,697,698],{"class":38,"line":140},[36,699,700],{},"    location \u002Fmedia\u002F {\n",[36,702,703],{"class":38,"line":146},[36,704,705],{},"        alias \u002Fsrv\u002Fmyapp\u002Fshared\u002Fmedia\u002F;\n",[36,707,708],{"class":38,"line":151},[36,709,710],{},"        expires 7d;\n",[36,712,713],{"class":38,"line":180},[36,714,681],{},[36,716,717],{"class":38,"line":193},[36,718,686],{},[36,720,722],{"class":38,"line":721},18,[36,723,691],{},[36,725,727],{"class":38,"line":726},19,[36,728,137],{},[14,730,731,732,735],{},"Use ",[33,733,734],{},"immutable"," only when filenames are content-hashed.",[14,737,738,739,744],{},"If static assets are not loading correctly, see ",[740,741,743],"a",{"href":742},"\u002Ffix-issues\u002Fflask-static-files-not-loading-in-production","Flask Static Files Not Loading in Production",".",[243,746,748],{"id":747},"_7-define-an-upstream-for-gunicorn-tcp-deployments","7. Define an upstream for Gunicorn TCP deployments",[14,750,751],{},"If Gunicorn listens on TCP, define an upstream:",[26,753,755],{"className":315,"code":754,"language":317,"meta":31,"style":31},"upstream flask_app {\n    server 127.0.0.1:8000;\n    keepalive 32;\n}\n",[33,756,757,762,767,772],{"__ignoreMap":31},[36,758,759],{"class":38,"line":39},[36,760,761],{},"upstream flask_app {\n",[36,763,764],{"class":38,"line":56},[36,765,766],{},"    server 127.0.0.1:8000;\n",[36,768,769],{"class":38,"line":80},[36,770,771],{},"    keepalive 32;\n",[36,773,774],{"class":38,"line":86},[36,775,137],{},[14,777,778],{},"If using a Unix socket, skip upstream keepalive and use the socket path directly.",[243,780,782],{"id":781},"_8-tune-proxy-behavior-for-flask-requests","8. Tune proxy behavior for Flask requests",[14,784,785,786,488],{},"Inside the dynamic request ",[33,787,300],{},[26,789,791],{"className":315,"code":790,"language":317,"meta":31,"style":31},"location \u002F {\n    proxy_pass http:\u002F\u002Fflask_app;\n    proxy_http_version 1.1;\n    proxy_set_header Connection \"\";\n    proxy_set_header Host $host;\n    proxy_set_header X-Real-IP $remote_addr;\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header X-Forwarded-Proto $scheme;\n\n    proxy_connect_timeout 5s;\n    proxy_send_timeout 60s;\n    proxy_read_timeout 60s;\n\n    proxy_buffering on;\n    proxy_buffers 16 16k;\n    proxy_buffer_size 16k;\n}\n",[33,792,793,798,803,808,813,818,823,828,833,837,842,847,852,856,861,866,871],{"__ignoreMap":31},[36,794,795],{"class":38,"line":39},[36,796,797],{},"location \u002F {\n",[36,799,800],{"class":38,"line":56},[36,801,802],{},"    proxy_pass http:\u002F\u002Fflask_app;\n",[36,804,805],{"class":38,"line":80},[36,806,807],{},"    proxy_http_version 1.1;\n",[36,809,810],{"class":38,"line":86},[36,811,812],{},"    proxy_set_header Connection \"\";\n",[36,814,815],{"class":38,"line":93},[36,816,817],{},"    proxy_set_header Host $host;\n",[36,819,820],{"class":38,"line":99},[36,821,822],{},"    proxy_set_header X-Real-IP $remote_addr;\n",[36,824,825],{"class":38,"line":105},[36,826,827],{},"    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n",[36,829,830],{"class":38,"line":110},[36,831,832],{},"    proxy_set_header X-Forwarded-Proto $scheme;\n",[36,834,835],{"class":38,"line":116},[36,836,90],{"emptyLinePlaceholder":89},[36,838,839],{"class":38,"line":122},[36,840,841],{},"    proxy_connect_timeout 5s;\n",[36,843,844],{"class":38,"line":128},[36,845,846],{},"    proxy_send_timeout 60s;\n",[36,848,849],{"class":38,"line":134},[36,850,851],{},"    proxy_read_timeout 60s;\n",[36,853,854],{"class":38,"line":140},[36,855,90],{"emptyLinePlaceholder":89},[36,857,858],{"class":38,"line":146},[36,859,860],{},"    proxy_buffering on;\n",[36,862,863],{"class":38,"line":151},[36,864,865],{},"    proxy_buffers 16 16k;\n",[36,867,868],{"class":38,"line":180},[36,869,870],{},"    proxy_buffer_size 16k;\n",[36,872,873],{"class":38,"line":193},[36,874,137],{},[14,876,877],{},"If using a Unix socket:",[26,879,881],{"className":315,"code":880,"language":317,"meta":31,"style":31},"location \u002F {\n    proxy_pass http:\u002F\u002Funix:\u002Frun\u002Fgunicorn.sock;\n    proxy_http_version 1.1;\n    proxy_set_header Connection \"\";\n    proxy_set_header Host $host;\n    proxy_set_header X-Real-IP $remote_addr;\n    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header X-Forwarded-Proto $scheme;\n\n    proxy_connect_timeout 5s;\n    proxy_send_timeout 60s;\n    proxy_read_timeout 60s;\n\n    proxy_buffering on;\n    proxy_buffers 16 16k;\n    proxy_buffer_size 16k;\n}\n",[33,882,883,887,892,896,900,904,908,912,916,920,924,928,932,936,940,944,948],{"__ignoreMap":31},[36,884,885],{"class":38,"line":39},[36,886,797],{},[36,888,889],{"class":38,"line":56},[36,890,891],{},"    proxy_pass http:\u002F\u002Funix:\u002Frun\u002Fgunicorn.sock;\n",[36,893,894],{"class":38,"line":80},[36,895,807],{},[36,897,898],{"class":38,"line":86},[36,899,812],{},[36,901,902],{"class":38,"line":93},[36,903,817],{},[36,905,906],{"class":38,"line":99},[36,907,822],{},[36,909,910],{"class":38,"line":105},[36,911,827],{},[36,913,914],{"class":38,"line":110},[36,915,832],{},[36,917,918],{"class":38,"line":116},[36,919,90],{"emptyLinePlaceholder":89},[36,921,922],{"class":38,"line":122},[36,923,841],{},[36,925,926],{"class":38,"line":128},[36,927,846],{},[36,929,930],{"class":38,"line":134},[36,931,851],{},[36,933,934],{"class":38,"line":140},[36,935,90],{"emptyLinePlaceholder":89},[36,937,938],{"class":38,"line":146},[36,939,860],{},[36,941,942],{"class":38,"line":151},[36,943,865],{},[36,945,946],{"class":38,"line":180},[36,947,870],{},[36,949,950],{"class":38,"line":193},[36,951,137],{},[243,953,955],{"id":954},"_9-use-a-full-server-block-baseline","9. Use a full server block baseline",[14,957,958],{},"Example complete baseline:",[26,960,962],{"className":315,"code":961,"language":317,"meta":31,"style":31},"upstream flask_app {\n    server 127.0.0.1:8000;\n    keepalive 32;\n}\n\nserver {\n    listen 80;\n    server_name example.com;\n\n    location \u002Fstatic\u002F {\n        alias \u002Fsrv\u002Fmyapp\u002Fcurrent\u002Fapp\u002Fstatic\u002F;\n        expires 30d;\n        add_header Cache-Control \"public, immutable\";\n        access_log off;\n        log_not_found off;\n    }\n\n    location \u002F {\n        proxy_pass http:\u002F\u002Fflask_app;\n        proxy_http_version 1.1;\n        proxy_set_header Connection \"\";\n        proxy_set_header Host $host;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_set_header X-Forwarded-Proto $scheme;\n        proxy_connect_timeout 5s;\n        proxy_send_timeout 60s;\n        proxy_read_timeout 60s;\n        proxy_buffering on;\n        proxy_buffers 16 16k;\n        proxy_buffer_size 16k;\n    }\n}\n",[33,963,964,968,972,976,980,984,988,992,996,1000,1004,1008,1012,1016,1020,1024,1028,1032,1037,1042,1048,1054,1060,1066,1072,1078,1084,1090,1096,1102,1108,1114,1119],{"__ignoreMap":31},[36,965,966],{"class":38,"line":39},[36,967,761],{},[36,969,970],{"class":38,"line":56},[36,971,766],{},[36,973,974],{"class":38,"line":80},[36,975,771],{},[36,977,978],{"class":38,"line":86},[36,979,137],{},[36,981,982],{"class":38,"line":93},[36,983,90],{"emptyLinePlaceholder":89},[36,985,986],{"class":38,"line":99},[36,987,642],{},[36,989,990],{"class":38,"line":105},[36,991,647],{},[36,993,994],{"class":38,"line":110},[36,995,652],{},[36,997,998],{"class":38,"line":116},[36,999,90],{"emptyLinePlaceholder":89},[36,1001,1002],{"class":38,"line":122},[36,1003,661],{},[36,1005,1006],{"class":38,"line":128},[36,1007,666],{},[36,1009,1010],{"class":38,"line":134},[36,1011,671],{},[36,1013,1014],{"class":38,"line":140},[36,1015,676],{},[36,1017,1018],{"class":38,"line":146},[36,1019,681],{},[36,1021,1022],{"class":38,"line":151},[36,1023,686],{},[36,1025,1026],{"class":38,"line":180},[36,1027,691],{},[36,1029,1030],{"class":38,"line":193},[36,1031,90],{"emptyLinePlaceholder":89},[36,1033,1034],{"class":38,"line":721},[36,1035,1036],{},"    location \u002F {\n",[36,1038,1039],{"class":38,"line":726},[36,1040,1041],{},"        proxy_pass http:\u002F\u002Fflask_app;\n",[36,1043,1045],{"class":38,"line":1044},20,[36,1046,1047],{},"        proxy_http_version 1.1;\n",[36,1049,1051],{"class":38,"line":1050},21,[36,1052,1053],{},"        proxy_set_header Connection \"\";\n",[36,1055,1057],{"class":38,"line":1056},22,[36,1058,1059],{},"        proxy_set_header Host $host;\n",[36,1061,1063],{"class":38,"line":1062},23,[36,1064,1065],{},"        proxy_set_header X-Real-IP $remote_addr;\n",[36,1067,1069],{"class":38,"line":1068},24,[36,1070,1071],{},"        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n",[36,1073,1075],{"class":38,"line":1074},25,[36,1076,1077],{},"        proxy_set_header X-Forwarded-Proto $scheme;\n",[36,1079,1081],{"class":38,"line":1080},26,[36,1082,1083],{},"        proxy_connect_timeout 5s;\n",[36,1085,1087],{"class":38,"line":1086},27,[36,1088,1089],{},"        proxy_send_timeout 60s;\n",[36,1091,1093],{"class":38,"line":1092},28,[36,1094,1095],{},"        proxy_read_timeout 60s;\n",[36,1097,1099],{"class":38,"line":1098},29,[36,1100,1101],{},"        proxy_buffering on;\n",[36,1103,1105],{"class":38,"line":1104},30,[36,1106,1107],{},"        proxy_buffers 16 16k;\n",[36,1109,1111],{"class":38,"line":1110},31,[36,1112,1113],{},"        proxy_buffer_size 16k;\n",[36,1115,1117],{"class":38,"line":1116},32,[36,1118,691],{},[36,1120,1122],{"class":38,"line":1121},33,[36,1123,137],{},[243,1125,1127],{"id":1126},"_10-check-system-limits","10. Check system limits",[14,1129,1130],{},"If you increase Nginx capacity, confirm the process is allowed enough open files.",[26,1132,1134],{"className":28,"code":1133,"language":30,"meta":31,"style":31},"cat \u002Fproc\u002F$(pgrep -o nginx)\u002Flimits | grep 'open files'\n",[33,1135,1136],{"__ignoreMap":31},[36,1137,1138,1141,1144,1147,1150,1153,1155,1158,1161,1163,1166],{"class":38,"line":39},[36,1139,1140],{"class":42},"cat",[36,1142,1143],{"class":46}," \u002Fproc\u002F",[36,1145,1146],{"class":205},"$(",[36,1148,1149],{"class":42},"pgrep",[36,1151,1152],{"class":201}," -o",[36,1154,198],{"class":46},[36,1156,1157],{"class":205},")",[36,1159,1160],{"class":46},"\u002Flimits",[36,1162,164],{"class":67},[36,1164,1165],{"class":42}," grep",[36,1167,1168],{"class":46}," 'open files'\n",[14,1170,1171],{},"If needed, adjust:",[282,1173,1174,1180,1185],{},[285,1175,1176,1177],{},"systemd ",[33,1178,1179],{},"LimitNOFILE",[285,1181,1182],{},[33,1183,1184],{},"\u002Fetc\u002Fsecurity\u002Flimits.conf",[285,1186,1187],{},"host kernel limits",[243,1189,1191],{"id":1190},"_11-reload-safely","11. Reload safely",[14,1193,1194],{},"Validate syntax before reload.",[26,1196,1198],{"className":28,"code":1197,"language":30,"meta":31,"style":31},"sudo nginx -t\nsudo systemctl reload nginx\n",[33,1199,1200,1208],{"__ignoreMap":31},[36,1201,1202,1204,1206],{"class":38,"line":39},[36,1203,43],{"class":42},[36,1205,198],{"class":46},[36,1207,263],{"class":201},[36,1209,1210,1212,1214,1216],{"class":38,"line":56},[36,1211,43],{"class":42},[36,1213,211],{"class":46},[36,1215,214],{"class":46},[36,1217,217],{"class":46},[14,1219,1220,1221,1224],{},"Do not reload if ",[33,1222,1223],{},"nginx -t"," fails.",[243,1226,1228],{"id":1227},"_12-benchmark-before-and-after","12. Benchmark before and after",[14,1230,1231],{},"Test headers, compression, and concurrency.",[26,1233,1235],{"className":28,"code":1234,"language":30,"meta":31,"style":31},"curl -I -H 'Accept-Encoding: gzip' https:\u002F\u002Fyour-domain\ncurl -I https:\u002F\u002Fyour-domain\u002Fstatic\u002Fapp.css\nwrk -t4 -c100 -d30s http:\u002F\u002F127.0.0.1\u002F\nab -n 1000 -c 50 http:\u002F\u002F127.0.0.1\u002F\n",[33,1236,1237,1254,1263,1280],{"__ignoreMap":31},[36,1238,1239,1242,1245,1248,1251],{"class":38,"line":39},[36,1240,1241],{"class":42},"curl",[36,1243,1244],{"class":201}," -I",[36,1246,1247],{"class":201}," -H",[36,1249,1250],{"class":46}," 'Accept-Encoding: gzip'",[36,1252,1253],{"class":46}," https:\u002F\u002Fyour-domain\n",[36,1255,1256,1258,1260],{"class":38,"line":56},[36,1257,1241],{"class":42},[36,1259,1244],{"class":201},[36,1261,1262],{"class":46}," https:\u002F\u002Fyour-domain\u002Fstatic\u002Fapp.css\n",[36,1264,1265,1268,1271,1274,1277],{"class":38,"line":80},[36,1266,1267],{"class":42},"wrk",[36,1269,1270],{"class":201}," -t4",[36,1272,1273],{"class":201}," -c100",[36,1275,1276],{"class":201}," -d30s",[36,1278,1279],{"class":46}," http:\u002F\u002F127.0.0.1\u002F\n",[36,1281,1282,1285,1288,1291,1294,1297],{"class":38,"line":86},[36,1283,1284],{"class":42},"ab",[36,1286,1287],{"class":201}," -n",[36,1289,1290],{"class":201}," 1000",[36,1292,1293],{"class":201}," -c",[36,1295,1296],{"class":201}," 50",[36,1298,1279],{"class":46},[14,1300,1301],{},"Compare:",[282,1303,1304,1307,1310,1313,1316],{},[285,1305,1306],{},"latency",[285,1308,1309],{},"requests per second",[285,1311,1312],{},"upstream timing",[285,1314,1315],{},"error rate",[285,1317,1318],{},"static asset response behavior",[243,1320,1322],{"id":1321},"_13-check-whether-the-bottleneck-is-really-nginx","13. Check whether the bottleneck is really Nginx",[14,1324,1325],{},"If Nginx is tuned and requests are still slow, the problem is often upstream:",[282,1327,1328,1331,1334,1337],{},[285,1329,1330],{},"Gunicorn worker count too low",[285,1332,1333],{},"blocking Flask code",[285,1335,1336],{},"slow database queries",[285,1338,1339],{},"external API latency",[14,1341,1342,1343,1347,1348,744],{},"If that applies, continue with ",[740,1344,1346],{"href":1345},"\u002Foptimize\u002Fflask-gunicorn-performance-tuning-guide","Flask Gunicorn Performance Tuning Guide"," and verify your deployment baseline in ",[740,1349,1351],{"href":1350},"\u002Fchecklist\u002Fflask-production-checklist-everything-you-must-do","Flask Production Checklist (Everything You Must Do)",[18,1353,1355],{"id":1354},"common-causes","Common Causes",[282,1357,1358,1368,1374,1377,1383,1390,1393,1396,1399,1405],{},[285,1359,1360,1361,462,1364,1367],{},"Static files routed through Gunicorn instead of Nginx → wastes app workers on file delivery → add dedicated ",[33,1362,1363],{},"location \u002Fstatic\u002F",[33,1365,1366],{},"location \u002Fmedia\u002F"," blocks.",[285,1369,1370,1371,1373],{},"Too few worker connections → concurrency stalls under burst traffic → raise ",[33,1372,367],{}," and confirm OS file descriptor limits.",[285,1375,1376],{},"No gzip or poor compression config → larger responses and slower transfer → enable gzip for text-based content.",[285,1378,1379,1380,1382],{},"Long keepalive timeout with low worker capacity → idle clients consume sockets → reduce ",[33,1381,472],{}," and raise worker capacity appropriately.",[285,1384,1385,1386,1389],{},"Proxy buffering disabled without a reason → increased upstream pressure and slower response handling → enable ",[33,1387,1388],{},"proxy_buffering on;"," for standard web traffic.",[285,1391,1392],{},"Access logging for every static request → unnecessary disk I\u002FO → disable access logs for static paths or move logs to faster storage.",[285,1394,1395],{},"Timeout values too low → valid requests fail under load → increase proxy read\u002Fsend timeouts only as needed.",[285,1397,1398],{},"Timeout values too high → slow upstreams tie up Nginx resources longer than needed → set practical limits and fix the app or Gunicorn if requests are slow.",[285,1400,1401,1402,744],{},"File metadata cache not enabled → repeated stat calls on many assets → configure ",[33,1403,1404],{},"open_file_cache",[285,1406,1407],{},"Underlying Gunicorn bottleneck → Nginx appears slow but upstream is saturated → tune Gunicorn workers, threads, or app code.",[18,1409,1411],{"id":1410},"debugging-section","Debugging Section",[14,1413,1414],{},"Check effective config:",[26,1416,1418],{"className":28,"code":1417,"language":30,"meta":31,"style":31},"sudo nginx -T | less\n",[33,1419,1420],{"__ignoreMap":31},[36,1421,1422,1424,1426,1428,1430],{"class":38,"line":39},[36,1423,43],{"class":42},[36,1425,198],{"class":46},[36,1427,272],{"class":201},[36,1429,164],{"class":67},[36,1431,277],{"class":42},[14,1433,1434],{},"Validate syntax before reload:",[26,1436,1438],{"className":28,"code":1437,"language":30,"meta":31,"style":31},"sudo nginx -t\n",[33,1439,1440],{"__ignoreMap":31},[36,1441,1442,1444,1446],{"class":38,"line":39},[36,1443,43],{"class":42},[36,1445,198],{"class":46},[36,1447,263],{"class":201},[14,1449,1450],{},"Inspect service state:",[26,1452,1454],{"className":28,"code":1453,"language":30,"meta":31,"style":31},"systemctl status nginx --no-pager\n",[33,1455,1456],{"__ignoreMap":31},[36,1457,1458,1461,1464,1466],{"class":38,"line":39},[36,1459,1460],{"class":42},"systemctl",[36,1462,1463],{"class":46}," status",[36,1465,198],{"class":46},[36,1467,1468],{"class":201}," --no-pager\n",[14,1470,1471],{},"Review recent Nginx errors:",[26,1473,1475],{"className":28,"code":1474,"language":30,"meta":31,"style":31},"sudo journalctl -u nginx -n 100 --no-pager\n",[33,1476,1477],{"__ignoreMap":31},[36,1478,1479,1481,1484,1487,1489,1491,1494],{"class":38,"line":39},[36,1480,43],{"class":42},[36,1482,1483],{"class":46}," journalctl",[36,1485,1486],{"class":201}," -u",[36,1488,198],{"class":46},[36,1490,1287],{"class":201},[36,1492,1493],{"class":201}," 100",[36,1495,1468],{"class":201},[14,1497,1498],{},"Tail logs:",[26,1500,1502],{"className":28,"code":1501,"language":30,"meta":31,"style":31},"sudo tail -f \u002Fvar\u002Flog\u002Fnginx\u002Ferror.log \u002Fvar\u002Flog\u002Fnginx\u002Faccess.log\n",[33,1503,1504],{"__ignoreMap":31},[36,1505,1506,1508,1511,1514,1517],{"class":38,"line":39},[36,1507,43],{"class":42},[36,1509,1510],{"class":46}," tail",[36,1512,1513],{"class":201}," -f",[36,1515,1516],{"class":46}," \u002Fvar\u002Flog\u002Fnginx\u002Ferror.log",[36,1518,1519],{"class":46}," \u002Fvar\u002Flog\u002Fnginx\u002Faccess.log\n",[14,1521,1522],{},"Inspect active connections:",[26,1524,1526],{"className":28,"code":1525,"language":30,"meta":31,"style":31},"ss -tanp | grep ':80\\|:443'\nss -tanp | grep nginx\n",[33,1527,1528,1543],{"__ignoreMap":31},[36,1529,1530,1533,1536,1538,1540],{"class":38,"line":39},[36,1531,1532],{"class":42},"ss",[36,1534,1535],{"class":201}," -tanp",[36,1537,164],{"class":67},[36,1539,1165],{"class":42},[36,1541,1542],{"class":46}," ':80\\|:443'\n",[36,1544,1545,1547,1549,1551,1553],{"class":38,"line":56},[36,1546,1532],{"class":42},[36,1548,1535],{"class":201},[36,1550,164],{"class":67},[36,1552,1165],{"class":42},[36,1554,217],{"class":46},[14,1556,1557],{},"Test response headers and compression:",[26,1559,1561],{"className":28,"code":1560,"language":30,"meta":31,"style":31},"curl -I -H 'Accept-Encoding: gzip' https:\u002F\u002Fyour-domain\n",[33,1562,1563],{"__ignoreMap":31},[36,1564,1565,1567,1569,1571,1573],{"class":38,"line":39},[36,1566,1241],{"class":42},[36,1568,1244],{"class":201},[36,1570,1247],{"class":201},[36,1572,1250],{"class":46},[36,1574,1253],{"class":46},[14,1576,1577],{},"Verify static files are served by Nginx:",[26,1579,1581],{"className":28,"code":1580,"language":30,"meta":31,"style":31},"curl -I https:\u002F\u002Fyour-domain\u002Fstatic\u002Fapp.css\n",[33,1582,1583],{"__ignoreMap":31},[36,1584,1585,1587,1589],{"class":38,"line":39},[36,1586,1241],{"class":42},[36,1588,1244],{"class":201},[36,1590,1262],{"class":46},[14,1592,1593],{},"Benchmark locally:",[26,1595,1597],{"className":28,"code":1596,"language":30,"meta":31,"style":31},"wrk -t4 -c100 -d30s http:\u002F\u002F127.0.0.1\u002F\nab -n 1000 -c 50 http:\u002F\u002F127.0.0.1\u002F\n",[33,1598,1599,1611],{"__ignoreMap":31},[36,1600,1601,1603,1605,1607,1609],{"class":38,"line":39},[36,1602,1267],{"class":42},[36,1604,1270],{"class":201},[36,1606,1273],{"class":201},[36,1608,1276],{"class":201},[36,1610,1279],{"class":46},[36,1612,1613,1615,1617,1619,1621,1623],{"class":38,"line":56},[36,1614,1284],{"class":42},[36,1616,1287],{"class":201},[36,1618,1290],{"class":201},[36,1620,1293],{"class":201},[36,1622,1296],{"class":201},[36,1624,1279],{"class":46},[14,1626,1627],{},"Check open file limits for Nginx workers:",[26,1629,1630],{"className":28,"code":1133,"language":30,"meta":31,"style":31},[33,1631,1632],{"__ignoreMap":31},[36,1633,1634,1636,1638,1640,1642,1644,1646,1648,1650,1652,1654],{"class":38,"line":39},[36,1635,1140],{"class":42},[36,1637,1143],{"class":46},[36,1639,1146],{"class":205},[36,1641,1149],{"class":42},[36,1643,1152],{"class":201},[36,1645,198],{"class":46},[36,1647,1157],{"class":205},[36,1649,1160],{"class":46},[36,1651,164],{"class":67},[36,1653,1165],{"class":42},[36,1655,1168],{"class":46},[14,1657,1658],{},"Add upstream timing to access logs if you need request timing detail:",[26,1660,1662],{"className":315,"code":1661,"language":317,"meta":31,"style":31},"log_format timing '$remote_addr - $host \"$request\" '\n                  'status=$status request_time=$request_time '\n                  'upstream_time=$upstream_response_time';\n\naccess_log \u002Fvar\u002Flog\u002Fnginx\u002Faccess.log timing;\n",[33,1663,1664,1669,1674,1679,1683],{"__ignoreMap":31},[36,1665,1666],{"class":38,"line":39},[36,1667,1668],{},"log_format timing '$remote_addr - $host \"$request\" '\n",[36,1670,1671],{"class":38,"line":56},[36,1672,1673],{},"                  'status=$status request_time=$request_time '\n",[36,1675,1676],{"class":38,"line":80},[36,1677,1678],{},"                  'upstream_time=$upstream_response_time';\n",[36,1680,1681],{"class":38,"line":86},[36,1682,90],{"emptyLinePlaceholder":89},[36,1684,1685],{"class":38,"line":93},[36,1686,1687],{},"access_log \u002Fvar\u002Flog\u002Fnginx\u002Faccess.log timing;\n",[14,1689,1690],{},"What to look for:",[282,1692,1693,1699,1705,1708,1715],{},[285,1694,1695,1696],{},"repeated ",[33,1697,1698],{},"upstream timed out",[285,1700,1701,1702],{},"frequent ",[33,1703,1704],{},"too many open files",[285,1706,1707],{},"static file requests hitting upstream instead of local alias paths",[285,1709,1710,1711,1714],{},"high ",[33,1712,1713],{},"$upstream_response_time"," with low Nginx request overhead",[285,1716,1717],{},"compression not applied to large text responses",[14,1719,1720,1721,1724,1725,744],{},"If you see ",[33,1722,1723],{},"502"," errors while tuning, use ",[740,1726,1728],{"href":1727},"\u002Ffix-issues\u002Ffix-flask-502-bad-gateway-step-by-step-guide","Fix Flask 502 Bad Gateway (Step-by-Step Guide)",[18,1730,1732],{"id":1731},"checklist","Checklist",[282,1734,1737,1749,1758,1766,1772,1778,1786,1792,1798,1804,1810],{"className":1735},[1736],"contains-task-list",[285,1738,1741,1745,1746,1748],{"className":1739},[1740],"task-list-item",[1742,1743],"input",{"disabled":89,"type":1744},"checkbox"," ",[33,1747,1223],{}," passes with no syntax errors.",[285,1750,1752,1745,1754,1757],{"className":1751},[1740],[1742,1753],{"disabled":89,"type":1744},[33,1755,1756],{},"worker_processes auto"," is enabled or intentionally set.",[285,1759,1761,1745,1763,1765],{"className":1760},[1740],[1742,1762],{"disabled":89,"type":1744},[33,1764,367],{}," matches expected concurrency and host limits.",[285,1767,1769,1771],{"className":1768},[1740],[1742,1770],{"disabled":89,"type":1744}," Static and media files are served directly by Nginx.",[285,1773,1775,1777],{"className":1774},[1740],[1742,1776],{"disabled":89,"type":1744}," Gzip is enabled for text-based responses.",[285,1779,1781,1745,1783,1785],{"className":1780},[1740],[1742,1782],{"disabled":89,"type":1744},[33,1784,1404],{}," is configured for static-heavy apps.",[285,1787,1789,1791],{"className":1788},[1740],[1742,1790],{"disabled":89,"type":1744}," Proxy headers to Gunicorn are set correctly.",[285,1793,1795,1797],{"className":1794},[1740],[1742,1796],{"disabled":89,"type":1744}," Keepalive and timeout values are explicitly defined.",[285,1799,1801,1803],{"className":1800},[1740],[1742,1802],{"disabled":89,"type":1744}," Nginx reload completes without downtime.",[285,1805,1807,1809],{"className":1806},[1740],[1742,1808],{"disabled":89,"type":1744}," Load test results improve or remain stable after changes.",[285,1811,1813,1815],{"className":1812},[1740],[1742,1814],{"disabled":89,"type":1744}," Error logs show no upstream or buffering regressions.",[18,1817,1819],{"id":1818},"related-guides","Related Guides",[282,1821,1822,1828,1832,1836],{},[285,1823,1824],{},[740,1825,1827],{"href":1826},"\u002Fdeploy\u002Fdeploy-flask-with-nginx-plus-gunicorn-step-by-step-guide","Deploy Flask with Nginx + Gunicorn (Step-by-Step Guide)",[285,1829,1830],{},[740,1831,1351],{"href":1350},[285,1833,1834],{},[740,1835,1728],{"href":1727},[285,1837,1838],{},[740,1839,743],{"href":742},[18,1841,1843],{"id":1842},"faq","FAQ",[14,1845,1846,1850,1853],{},[1847,1848,1849],"strong",{},"Q: Should I use a Unix socket or TCP between Nginx and Gunicorn?",[1851,1852],"br",{},"\nA: Use a Unix socket for a single-host setup unless TCP fits your deployment model better. The larger performance gains usually come from correct worker, buffering, and static file settings.",[14,1855,1856,1863,1865],{},[1847,1857,1858,1859,1862],{},"Q: Should ",[33,1860,1861],{},"proxy_buffering"," be on for Flask?",[1851,1864],{},"\nA: Yes for most standard web requests. Disable it only for streaming or long-lived response patterns that require immediate flushing.",[14,1867,1868,1871,1873],{},[1847,1869,1870],{},"Q: Does gzip help API responses?",[1851,1872],{},"\nA: Yes. JSON responses often compress well and reduce bandwidth and transfer time.",[14,1875,1876,1882,1884],{},[1847,1877,1878,1879,1881],{},"Q: Will increasing ",[33,1880,367],{}," fix application slowness?",[1851,1883],{},"\nA: No. It increases concurrency capacity but does not make slow Flask code or database queries faster.",[14,1886,1887,1890,1892],{},[1847,1888,1889],{},"Q: Should I cache dynamic Flask pages in Nginx?",[1851,1891],{},"\nA: Only if your response behavior is safe to cache. Start with static asset caching first.",[18,1894,1896],{"id":1895},"final-takeaway","Final Takeaway",[14,1898,1899],{},"Tune Nginx to do edge work efficiently: manage connections well, compress text responses, serve static files directly, and keep proxy behavior clean. If performance remains poor after that, the next bottleneck is usually Gunicorn or the Flask app itself.",[1901,1902,1903],"style",{},"html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":31,"searchDepth":56,"depth":56,"links":1905},[1906,1907,1908,1923,1924,1925,1926,1927,1928],{"id":20,"depth":56,"text":21},{"id":227,"depth":56,"text":228},{"id":240,"depth":56,"text":241,"children":1909},[1910,1911,1912,1913,1914,1915,1916,1917,1918,1919,1920,1921,1922],{"id":245,"depth":80,"text":246},{"id":304,"depth":80,"text":305},{"id":383,"depth":80,"text":384},{"id":482,"depth":80,"text":483},{"id":519,"depth":80,"text":520},{"id":625,"depth":80,"text":626},{"id":747,"depth":80,"text":748},{"id":781,"depth":80,"text":782},{"id":954,"depth":80,"text":955},{"id":1126,"depth":80,"text":1127},{"id":1190,"depth":80,"text":1191},{"id":1227,"depth":80,"text":1228},{"id":1321,"depth":80,"text":1322},{"id":1354,"depth":56,"text":1355},{"id":1410,"depth":56,"text":1411},{"id":1731,"depth":56,"text":1732},{"id":1818,"depth":56,"text":1819},{"id":1842,"depth":56,"text":1843},{"id":1895,"depth":56,"text":1896},"Complete guide on flask nginx performance tuning guide for Flask production environments.","md",{"ogTitle":5,"ogDescription":1929,"twitterCard":1932,"robots":1933,"canonical":1934},"summary_large_image","index, follow","https:\u002F\u002Fflask-deployment.com\u002Foptimize\u002Fflask-nginx-performance-tuning-guide","\u002Foptimize\u002Fflask-nginx-performance-tuning-guide",{"title":5,"description":1929},"optimize\u002Fflask-nginx-performance-tuning-guide","e7dTKQCo_KowGh9GREzTVO7-UNm_iI9L-9xBlzoVeGo",1776805765781]