{"id":15908,"date":"2026-04-25T23:23:00","date_gmt":"2026-04-25T15:23:00","guid":{"rendered":"https:\/\/top.duoku.icu\/libs\/15908.html"},"modified":"2026-04-25T23:23:00","modified_gmt":"2026-04-25T15:23:00","slug":"nginx-%e8%af%a6%e7%bb%86%e4%bd%bf%e7%94%a8%e6%95%99%e7%a8%8b%ef%bc%9a%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a","status":"publish","type":"post","link":"https:\/\/www.srclibs.com\/index.php\/2026\/04\/25\/nginx-%e8%af%a6%e7%bb%86%e4%bd%bf%e7%94%a8%e6%95%99%e7%a8%8b%ef%bc%9a%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e7%b2%be%e9%80%9a\/","title":{"rendered":"Nginx \u8be6\u7ec6\u4f7f\u7528\u6559\u7a0b\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a"},"content":{"rendered":"<div style=\"text-align:center;margin:30px 0;\"><img decoding=\"async\" src=\"https:\/\/top.duoku.icu\/wp-content\/uploads\/2026\/04\/image-81.png\" alt=\"Nginx \u8be6\u7ec6\u4f7f\u7528\u6559\u7a0b\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a\" style=\"max-width:100%;height:auto;border-radius:12px;box-shadow:0 4px 12px rgba(0,0,0,0.1);\"><\/div>\n<h1>Nginx \u8be6\u7ec6\u4f7f\u7528\u6559\u7a0b\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a<\/h1>\n<h2>\u524d\u8a00<\/h2>\n<p>Nginx\uff08\u53d1\u97f3\u4e3a &#8220;engine-x&#8221;\uff09\u662f\u4e00\u6b3e\u9ad8\u6027\u80fd\u7684 HTTP \u548c\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u4ee5\u5176\u9ad8\u5e76\u53d1\u5904\u7406\u80fd\u529b\u3001\u4f4e\u5185\u5b58\u6d88\u8017\u548c\u51fa\u8272\u7684\u7a33\u5b9a\u6027\u800c\u95fb\u540d\u3002\u672c\u6587\u6863\u5c06\u5e26\u60a8\u4ece\u96f6\u57fa\u7840\u5f00\u59cb\uff0c\u9010\u6b65\u638c\u63e1 Nginx \u7684\u6838\u5fc3\u529f\u80fd\u4e0e\u9ad8\u7ea7\u5e94\u7528\u3002<\/p>\n<p>&#8212;<\/p>\n<h2>\u4e00\u3001Nginx \u6838\u5fc3\u529f\u80fd<\/h2>\n<h3>1.1 \u4e3b\u8981\u7279\u6027<\/h3>\n<ul>\n<li><strong>\u9ad8\u5e76\u53d1\u6027\u80fd<\/strong>\uff1a\u91c7\u7528\u4e8b\u4ef6\u9a71\u52a8\u67b6\u6784\uff0c\u5355\u8fdb\u7a0b\u53ef\u5904\u7406\u6570\u5343\u5e76\u53d1\u8fde\u63a5<\/li>\n<li><strong>\u53cd\u5411\u4ee3\u7406<\/strong>\uff1a\u5c06\u5ba2\u6237\u7aef\u8bf7\u6c42\u8f6c\u53d1\u5230\u540e\u7aef\u670d\u52a1\u5668<\/li>\n<li><strong>\u8d1f\u8f7d\u5747\u8861<\/strong>\uff1a\u5206\u914d\u6d41\u91cf\u5230\u591a\u4e2a\u540e\u7aef\u670d\u52a1\u5668<\/li>\n<li><strong>\u9759\u6001\u8d44\u6e90\u670d\u52a1<\/strong>\uff1a\u9ad8\u6548\u5904\u7406\u9759\u6001\u6587\u4ef6\uff08\u56fe\u7247\u3001CSS\u3001JS \u7b49\uff09<\/li>\n<li><strong>HTTP \u7f13\u5b58<\/strong>\uff1a\u5185\u7f6e\u7f13\u5b58\u673a\u5236\u63d0\u5347\u54cd\u5e94\u901f\u5ea6<\/li>\n<li><strong>SSL\/TLS \u7ec8\u6b62<\/strong>\uff1a\u5904\u7406 HTTPS \u52a0\u5bc6\u89e3\u5bc6<\/li>\n<\/ul>\n<h3>1.2 \u67b6\u6784\u4f18\u52bf<\/h3>\n<p>\u4e0e\u4f20\u7edf Web \u670d\u52a1\u5668\u76f8\u6bd4\uff0cNginx \u91c7\u7528\u4e86\u5f02\u6b65\u975e\u963b\u585e I\/O \u6a21\u578b\uff0c\u80fd\u591f\u4ee5\u6781\u5c11\u7684\u8d44\u6e90\u5904\u7406\u6d77\u91cf\u5e76\u53d1\u8fde\u63a5\uff0c\u7279\u522b\u9002\u5408\u9ad8\u6d41\u91cf\u7f51\u7ad9\u548c API \u7f51\u5173\u573a\u666f\u3002<\/p>\n<p>&#8212;<\/p>\n<h2>\u4e8c\u3001\u5b89\u88c5\u4e0e\u57fa\u7840\u914d\u7f6e<\/h2>\n<h3>2.1 \u5b89\u88c5\u65b9\u5f0f<\/h3>\n<h4>Linux \u7cfb\u7edf\uff08Ubuntu\/Debian\uff09<\/h4>\n<pre><code># \u66f4\u65b0\u8f6f\u4ef6\u6e90\nsudo apt update\n\n<h1>\u5b89\u88c5 Nginx<\/h1>\nsudo apt install nginx\n\n<h1>\u68c0\u67e5\u7248\u672c<\/h1>\nnginx -v\n<\/code><\/pre>\n<h4>Linux \u7cfb\u7edf\uff08CentOS\/RHEL\uff09<\/h4>\n<pre><code># \u5b89\u88c5 EPEL \u4ed3\u5e93\nsudo yum install epel-release\n\n<h1>\u5b89\u88c5 Nginx<\/h1>\nsudo yum install nginx\n\n<h1>\u542f\u52a8\u670d\u52a1<\/h1>\nsudo systemctl start nginx\nsudo systemctl enable nginx\n<\/code><\/pre>\n<h4>macOS\uff08\u901a\u8fc7 Homebrew\uff09<\/h4>\n<pre><code>brew install nginx\nbrew services start nginx\n<\/code><\/pre>\n<h3>2.2 \u76ee\u5f55\u7ed3\u6784<\/h3>\n<pre><code>\/etc\/nginx\/\n\u251c\u2500\u2500 nginx.conf          # \u4e3b\u914d\u7f6e\u6587\u4ef6\n\u251c\u2500\u2500 sites-available\/    # \u53ef\u7528\u7ad9\u70b9\u914d\u7f6e\n\u251c\u2500\u2500 sites-enabled\/      # \u542f\u7528\u7ad9\u70b9\u914d\u7f6e\n\u251c\u2500\u2500 conf.d\/             # \u989d\u5916\u914d\u7f6e\u76ee\u5f55\n\u2514\u2500\u2500 ssl\/                # SSL \u8bc1\u4e66\u76ee\u5f55\n<\/code><\/pre>\n<h3>2.3 \u57fa\u7840\u914d\u7f6e\u793a\u4f8b<\/h3>\n<p>&#8220;`nginx<br \/>\nworker_processes auto;<br \/>\nerror_log \/var\/log\/nginx\/error.log warn;<br \/>\npid \/var\/run\/nginx.pid;<\/p>\n<p>events {<br \/>\n    worker_connections 1024;<br \/>\n    use epoll;<br \/>\n    multi_accept on;<br \/>\n}<\/p>\n<p>http {<br \/>\n    include \/etc\/nginx\/mime.types;<br \/>\n    default_type application\/octet-stream;<\/p>\n<p>    # \u65e5\u5fd7\u683c\u5f0f<br \/>\n    log_format main &#8216;$remote_addr &#8211; $remote_user [$time_local] &#8220;$request&#8221; &#8216;<br \/>\n                    &#8216;$status $body_bytes_sent &#8220;$http_referer&#8221; &#8216;<br \/>\n                    &#8216;&#8221;$http_user_agent&#8221; &#8220;$http_x_forwarded_for&#8221;&#8216;;<\/p>\n<p>    access_log \/var\/log\/nginx\/access.log main;<\/p>\n<p>    sendfile on;<br \/>\n    tcp_nopush on;<br \/>\n    tcp_nodelay on;<br \/>\n    keepalive_timeout 65;<br \/>\n    types_hash_max_size 2048;<\/p>\n<p>    gzip on;<br \/>\n    gzip_min_length 1000;<br \/>\n    gzip_comp_level 6;<br \/>\n    gzip_types text\/plain text\/css application\/json application\/javascript;<\/p>\n<p>    include \/etc\/nginx\/conf.d\/*.conf;<br \/>\n}<\/p>\n<pre><code>\n---\n\n<h2>\u4e09\u3001\u5e38\u7528\u6307\u4ee4\u4e0e\u7ba1\u7406<\/h2>\n\n<h3>3.1 \u7cfb\u7edf\u670d\u52a1\u7ba1\u7406<\/h3>\n\n<\/code><\/pre>\n<p>bash<\/p>\n<h1>\u542f\u52a8\u670d\u52a1<\/h1>\n<p>sudo systemctl start nginx<\/p>\n<h1>\u505c\u6b62\u670d\u52a1<\/h1>\n<p>sudo systemctl stop nginx<\/p>\n<h1>\u91cd\u542f\u670d\u52a1<\/h1>\n<p>sudo systemctl restart nginx<\/p>\n<h1>\u91cd\u8f7d\u914d\u7f6e\uff08\u4e0d\u4e2d\u65ad\u670d\u52a1\uff09<\/h1>\n<p>sudo systemctl reload nginx<\/p>\n<h1>\u67e5\u770b\u72b6\u6001<\/h1>\n<p>sudo systemctl status nginx<\/p>\n<pre><code>\n<h3>3.2 Nginx \u547d\u4ee4<\/h3>\n\n<\/code><\/pre>\n<p>bash<\/p>\n<h1>\u6d4b\u8bd5\u914d\u7f6e\u6587\u4ef6\u8bed\u6cd5<\/h1>\n<p>sudo nginx -t<\/p>\n<h1>\u663e\u793a\u7248\u672c<\/h1>\n<p>nginx -v<\/p>\n<h1>\u663e\u793a\u5e2e\u52a9<\/h1>\n<p>nginx -h<\/p>\n<h1>\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u542f\u52a8<\/h1>\n<p>nginx -c \/path\/to\/nginx.conf<\/p>\n<h1>\u6307\u5b9a\u914d\u7f6e\u6587\u4ef6\u91cd\u8f7d<\/h1>\n<p>nginx -s reload<\/p>\n<h1>\u505c\u6b62\u670d\u52a1<\/h1>\n<p>nginx -s stop<\/p>\n<h1>\u4f18\u96c5\u9000\u51fa<\/h1>\n<p>nginx -s quit<\/p>\n<pre><code>\n---\n\n<h2>\u56db\u3001\u865a\u62df\u4e3b\u673a\u914d\u7f6e<\/h2>\n\n<h3>4.1 \u57fa\u4e8e\u57df\u540d\u7684\u865a\u62df\u4e3b\u673a<\/h3>\n\n<\/code><\/pre>\n<p>nginx<br \/>\nserver {<br \/>\n    listen 80;<br \/>\n    server_name example.com www.example.com;<\/p>\n<p>    root \/var\/www\/example.com;<br \/>\n    index index.html index.htm;<\/p>\n<p>    location \/ {<br \/>\n        try_files $uri $uri\/ =404;<br \/>\n    }<\/p>\n<p>    error_page 404 \/404.html;<br \/>\n    error_page 500 502 503 504 \/50x.html;<br \/>\n}<\/p>\n<pre><code>\n<h3>4.2 \u57fa\u4e8e\u7aef\u53e3\u7684\u865a\u62df\u4e3b\u673a<\/h3>\n\n<\/code><\/pre>\n<p>nginx<br \/>\nserver {<br \/>\n    listen 8080;<br \/>\n    server_name api.example.com;<\/p>\n<p>    root \/var\/www\/api;<\/p>\n<p>    location \/ {<br \/>\n        proxy_pass http:\/\/localhost:3000;<br \/>\n    }<br \/>\n}<\/p>\n<pre><code>\n---\n\n<h2>\u4e94\u3001\u53cd\u5411\u4ee3\u7406<\/h2>\n\n<h3>5.1 \u57fa\u7840\u53cd\u5411\u4ee3\u7406<\/h3>\n\n<\/code><\/pre>\n<p>nginx<br \/>\nserver {<br \/>\n    listen 80;<br \/>\n    server_name api.example.com;<\/p>\n<p>    location \/ {<br \/>\n        proxy_pass http:\/\/backend_server;<br \/>\n        proxy_set_header Host $host;<br \/>\n        proxy_set_header X-Real-IP $remote_addr;<br \/>\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br \/>\n        proxy_set_header X-Forwarded-Proto $scheme;<\/p>\n<p>        proxy_connect_timeout 60s;<br \/>\n        proxy_send_timeout 60s;<br \/>\n        proxy_read_timeout 60s;<br \/>\n    }<br \/>\n}<\/p>\n<pre><code>\n<h3>5.2 WebSocket \u652f\u6301<\/h3>\n\n<\/code><\/pre>\n<p>nginx<br \/>\nserver {<br \/>\n    listen 80;<br \/>\n    server_name websocket.example.com;<\/p>\n<p>    location \/ws {<br \/>\n        proxy_pass http:\/\/websocket_backend;<br \/>\n        proxy_http_version 1.1;<br \/>\n        proxy_set_header Upgrade $http_upgrade;<br \/>\n        proxy_set_header Connection &#8220;upgrade&#8221;;<br \/>\n        proxy_set_header Host $host;<\/p>\n<p>        proxy_read_timeout 86400s;<br \/>\n    }<br \/>\n}<\/p>\n<pre><code>\n<h3>5.3 \u9759\u6001\u8d44\u6e90\u4ee3\u7406<\/h3>\n\n<\/code><\/pre>\n<p>nginx<br \/>\nserver {<br \/>\n    listen 80;<br \/>\n    server_name static.example.com;<\/p>\n<p>    location \/ {<br \/>\n        root \/var\/www\/static;<br \/>\n        expires 30d;<br \/>\n        add_header Cache-Control &#8220;public, immutable&#8221;;<br \/>\n    }<br \/>\n}<\/p>\n<pre><code>\n---\n\n<h2>\u516d\u3001\u8d1f\u8f7d\u5747\u8861\u914d\u7f6e<\/h2>\n\n<h3>6.1 \u8d1f\u8f7d\u5747\u8861\u7b56\u7565<\/h3>\n\n<\/code><\/pre>\n<p>nginx<br \/>\nupstream backend_pool {<br \/>\n    # \u8f6e\u8be2\uff08\u9ed8\u8ba4\uff09<br \/>\n    server backend1.example.com weight=3;<br \/>\n    server backend2.example.com weight=2;<br \/>\n    server backend3.example.com;<\/p>\n<p>    # \u6216\u4f7f\u7528\u6743\u91cd\u914d\u7f6e<br \/>\n    # ip_hash;<\/p>\n<p>    # \u6216\u914d\u7f6e\u5907\u7528\u670d\u52a1\u5668<br \/>\n    # server backend4.example.com backup;<\/p>\n<p>    # \u6700\u5927\u8fde\u63a5\u6570\u9650\u5236<br \/>\n    # keepalive 32;<br \/>\n}<\/p>\n<p>server {<br \/>\n    listen 80;<br \/>\n    server_name app.example.com;<\/p>\n<p>    location \/ {<br \/>\n        proxy_pass http:\/\/backend_pool;<br \/>\n        proxy_set_header Host $host;<br \/>\n        proxy_set_header X-Real-IP $remote_addr;<br \/>\n    }<br \/>\n}<\/p>\n<pre><code>\n<h3>6.2 \u5065\u5eb7\u68c0\u67e5\u914d\u7f6e<\/h3>\n\n<\/code><\/pre>\n<p>nginx<br \/>\nupstream api_servers {<br \/>\n    server 192.168.1.10:8080 max_fails=3 fail_timeout=30s;<br \/>\n    server 192.168.1.11:8080 max_fails=3 fail_timeout=30s;<br \/>\n    server 192.168.1.12:8080 max_fails=3 fail_timeout=30s backup;<br \/>\n}<\/p>\n<p>server {<br \/>\n    listen 80;<\/p>\n<p>    location \/api {<br \/>\n        proxy_pass http:\/\/api_servers;<br \/>\n        proxy_next_upstream error timeout http_502 http_503;<br \/>\n    }<br \/>\n}<\/p>\n<pre><code>\n<h3>6.3 \u8d1f\u8f7d\u5747\u8861\u7b97\u6cd5\u5bf9\u6bd4<\/h3>\n\n<table border=\"1\" cellpadding=\"5\">\n  <tr>\n    <th>\u7b97\u6cd5<\/th>\n    <th>\u63cf\u8ff0<\/th>\n    <th>\u9002\u7528\u573a\u666f<\/th>\n  <\/tr>\n  <tr>\n    <td>\u8f6e\u8be2\uff08round_robin\uff09<\/td>\n    <td>\u4f9d\u6b21\u5206\u914d\u8bf7\u6c42<\/td>\n    <td>\u670d\u52a1\u5668\u6027\u80fd\u76f8\u8fd1<\/td>\n  <\/tr>\n  <tr>\n    <td>\u52a0\u6743\u8f6e\u8be2\uff08weight\uff09<\/td>\n    <td>\u6309\u6743\u91cd\u5206\u914d\u8bf7\u6c42<\/td>\n    <td>\u670d\u52a1\u5668\u6027\u80fd\u4e0d\u540c<\/td>\n  <\/tr>\n  <tr>\n    <td>IP \u54c8\u5e0c\uff08ip_hash\uff09<\/td>\n    <td>\u540c\u4e00 IP \u59cb\u7ec8\u5206\u914d\u5230\u540c\u4e00\u670d\u52a1\u5668<\/td>\n    <td>\u9700\u8981\u4f1a\u8bdd\u4fdd\u6301<\/td>\n  <\/tr>\n  <tr>\n    <td>\u6700\u5c11\u8fde\u63a5\uff08least_conn\uff09<\/td>\n    <td>\u5206\u914d\u7ed9\u6d3b\u8dc3\u8fde\u63a5\u6700\u5c11\u7684\u670d\u52a1\u5668<\/td>\n    <td>\u8bf7\u6c42\u5904\u7406\u65f6\u957f\u4e0d\u4e00<\/td>\n  <\/tr>\n<\/table>\n\n---\n\n<h2>\u4e03\u3001\u9ad8\u7ea7\u529f\u80fd\u914d\u7f6e<\/h2>\n\n<h3>7.1 SSL\/TLS \u914d\u7f6e<\/h3>\n\n<\/code><\/pre>\n<p>nginx<br \/>\nserver {<br \/>\n    listen 443 ssl http2;<br \/>\n    server_name secure.example.com;<\/p>\n<p>    ssl_certificate \/etc\/nginx\/ssl\/example.com.crt;<br \/>\n    ssl_certificate_key \/etc\/nginx\/ssl\/example.com.key;<\/p>\n<p>    ssl_protocols TLSv1.2 TLSv1.3;<br \/>\n    ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512;<br \/>\n    ssl_prefer_server_ciphers off;<br \/>\n    ssl_session_cache shared:SSL:10m;<br \/>\n    ssl_session_timeout 10m;<\/p>\n<p>    location \/ {<br \/>\n        root \/var\/www\/html;<br \/>\n    }<br \/>\n}<\/p>\n<pre><code>\n<h3>7.2 URL \u91cd\u5199\u4e0e\u91cd\u5b9a\u5411<\/h3>\n\n<\/code><\/pre>\n<p>nginx<\/p>\n<h1>\u6c38\u4e45\u91cd\u5b9a\u5411<\/h1>\n<p>server {<br \/>\n    listen 80;<br \/>\n    server_name old.example.com;<br \/>\n    return 301 https:\/\/new.example.com$request_uri;<br \/>\n}<\/p>\n<h1>\u6761\u4ef6\u91cd\u5199<\/h1>\n<p>server {<br \/>\n    listen 80;<br \/>\n    server_name api.example.com;<\/p>\n<p>    location \/v1\/ {<br \/>\n        rewrite ^\/v1\/(.*)$ \/$1 break;<br \/>\n        proxy_pass http:\/\/backend;<br \/>\n    }<\/p>\n<p>    location \/v2\/ {<br \/>\n        rewrite ^\/v2\/(.*)$ \/api\/v2\/$1 break;<br \/>\n        proxy_pass http:\/\/backend;<br \/>\n    }<br \/>\n}<\/p>\n<pre><code>\n<h3>7.3 \u8bbf\u95ee\u63a7\u5236<\/h3>\n\n<\/code><\/pre>\n<p>nginx<\/p>\n<h1>IP \u9ed1\u767d\u540d\u5355<\/h1>\n<p>server {<br \/>\n    listen 80;<br \/>\n    server_name admin.example.com;<\/p>\n<p>    allow 192.168.1.0\/24;<br \/>\n    deny all;<\/p>\n<p>    location \/ {<br \/>\n        proxy_pass http:\/\/backend;<br \/>\n    }<br \/>\n}<\/p>\n<h1>\u57fa\u672c\u8ba4\u8bc1<\/h1>\n<p>server {<br \/>\n    listen 80;<br \/>\n    server_name secure.example.com;<\/p>\n<p>    location \/admin {<br \/>\n        auth_basic &#8220;Restricted Access&#8221;;<br \/>\n        auth_basic_user_file \/etc\/nginx\/.htpasswd;<br \/>\n        proxy_pass http:\/\/backend;<br \/>\n    }<br \/>\n}<\/p>\n<pre><code>\n<h3>7.4 \u9650\u6d41\u4e0e\u901f\u7387\u9650\u5236<\/h3>\n\n<\/code><\/pre>\n<p>nginx<\/p>\n<h1>\u5b9a\u4e49\u9650\u6d41\u533a\u57df<\/h1>\n<p>limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r\/s;<br \/>\nlimit_conn_zone $binary_remote_addr zone=conn_limit:10m;<\/p>\n<p>server {<br \/>\n    listen 80;<br \/>\n    server_name api.example.com;<\/p>\n<p>    location \/api {<br \/>\n        limit_req zone=api_limit burst=20 nodelay;<br \/>\n        limit_conn conn_limit 10;<\/p>\n<p>        proxy_pass http:\/\/backend;<br \/>\n    }<br \/>\n}<\/p>\n<pre><code>\n---\n\n<h2>\u516b\u3001\u6027\u80fd\u4f18\u5316\u6700\u4f73\u5b9e\u8df5<\/h2>\n\n<h3>8.1 \u5185\u6838\u53c2\u6570\u8c03\u4f18<\/h3>\n\n<\/code><\/pre>\n<p>bash<\/p>\n<h1>\/etc\/sysctl.conf<\/h1>\n<p>net.core.somaxconn = 65535<br \/>\nnet.ipv4.tcp_max_syn_backlog = 65535<br \/>\nnet.ipv4.tcp_fin_timeout = 30<br \/>\nnet.ipv4.tcp_keepalive_time = 1200<br \/>\nnet.ipv4.tcp_keepalive_probes = 5<br \/>\nnet.ipv4.tcp_keepalive_intvl = 15<\/p>\n<pre><code>\n<h3>8.2 Nginx \u6027\u80fd\u4f18\u5316\u53c2\u6570<\/h3>\n\n<\/code><\/pre>\n<p>nginx<br \/>\nworker_processes auto;<br \/>\nworker_rlimit_nofile 65535;<\/p>\n<p>events {<br \/>\n    worker_connections 65535;<br \/>\n    use epoll;<br \/>\n    multi_accept on;<br \/>\n}<\/p>\n<p>http {<br \/>\n    sendfile on;<br \/>\n    tcp_nopush on;<br \/>\n    tcp_nodelay on;<\/p>\n<p>    keepalive_timeout 65;<br \/>\n    keepalive_requests 1000;<\/p>\n<p>    client_max_body_size 10M;<br \/>\n    client_body_buffer_size 128k;<br \/>\n    client_header_buffer_size 1k;<br \/>\n    large_client_header_buffers 4 8k;<\/p>\n<p>    gzip on;<br \/>\n    gzip_comp_level 5;<br \/>\n    gzip_min_length 256;<br \/>\n    gzip_proxied any;<\/p>\n<p>    proxy_buffering on;<br \/>\n    proxy_buffer_size 4k;<br \/>\n    proxy_buffers 8 4k;<br \/>\n}<\/p>\n<pre><code>\n---\n\n<h2>\u4e5d\u3001\u6545\u969c\u6392\u67e5\u6280\u5de7<\/h2>\n\n<h3>9.1 \u67e5\u770b\u65e5\u5fd7<\/h3>\n\n<\/code><\/pre>\n<p>bash<\/p>\n<h1>\u5b9e\u65f6\u67e5\u770b\u9519\u8bef\u65e5\u5fd7<\/h1>\n<p>tail -f \/var\/log\/nginx\/error.log<\/p>\n<h1>\u67e5\u770b\u8bbf\u95ee\u65e5\u5fd7<\/h1>\n<p>tail -f \/var\/log\/nginx\/access.log<\/p>\n<h1>\u5206\u6790\u9519\u8bef\u9891\u7387<\/h1>\n<p>grep -c &#8220;error&#8221; \/var\/log\/nginx\/error.log<\/p>\n<pre><code>\n<h3>9.2 \u6d4b\u8bd5\u914d\u7f6e\u6587\u4ef6<\/h3>\n\n<\/code><\/pre>\n<p>bash<\/p>\n<h1>\u6d4b\u8bd5\u914d\u7f6e\u8bed\u6cd5<\/h1>\n<p>sudo nginx -t<\/p>\n<h1>\u5982\u679c\u5931\u8d25\u67e5\u770b\u8be6\u7ec6\u9519\u8bef<\/h1>\n<p>sudo nginx -t 2>&#038;1<\/p>\n<pre><code>\n<h3>9.3 \u5e38\u7528\u8bca\u65ad\u547d\u4ee4<\/h3>\n\n<\/code><\/pre>\n<p>bash<\/p>\n<h1>\u68c0\u67e5\u7aef\u53e3\u76d1\u542c<\/h1>\n<p>sudo netstat -tulpn | grep nginx<\/p>\n<h1>\u68c0\u67e5\u8fdb\u7a0b\u72b6\u6001<\/h1>\n<p>ps aux | grep nginx<\/p>\n<h1>\u67e5\u770b\u8fde\u63a5\u6570<\/h1>\n<p>ss -tn state established | grep :80 | wc -l<br \/>\n&#8220;`<\/p>\n<p>&#8212;<\/p>\n<h2>\u7ed3\u8bed<\/h2>\n<p>Nginx \u662f\u4e00\u6b3e\u529f\u80fd\u5f3a\u5927\u3001\u914d\u7f6e\u7075\u6d3b\u7684 Web \u670d\u52a1\u5668\u548c\u53cd\u5411\u4ee3\u7406\u5de5\u5177\u3002\u901a\u8fc7\u672c\u6587\u6863\u7684\u5b66\u4e60\uff0c\u60a8\u5df2\u7ecf\u638c\u63e1\u4e86\uff1a<\/p>\n<ol>\n<li><strong>\u57fa\u7840\u5b89\u88c5\u4e0e\u914d\u7f6e<\/strong> &#8211; \u4e86\u89e3\u76ee\u5f55\u7ed3\u6784\u548c\u6838\u5fc3\u914d\u7f6e\u9879<\/li>\n<li><strong>\u865a\u62df\u4e3b\u673a\u914d\u7f6e<\/strong> &#8211; \u652f\u6301\u57df\u540d\u548c\u7aef\u53e3\u7684\u591a\u7ad9\u70b9\u90e8\u7f72<\/li>\n<li><strong>\u53cd\u5411\u4ee3\u7406\u529f\u80fd<\/strong> &#8211; \u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u540e\u7aef\u670d\u52a1<\/li>\n<li><strong>\u8d1f\u8f7d\u5747\u8861<\/strong> &#8211; \u5408\u7406\u5206\u914d\u6d41\u91cf\u5230\u591a\u4e2a\u670d\u52a1\u5668<\/li>\n<li><strong>\u9ad8\u7ea7\u529f\u80fd<\/strong> &#8211; SSL\u3001\u9650\u6d41\u3001\u8bbf\u95ee\u63a7\u5236\u7b49<\/li>\n<\/ul>\n<p>\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u5efa\u8bae\uff1a<\/p>\n<ul>\n<li>\u5b9a\u671f\u6d4b\u8bd5\u914d\u7f6e\u6587\u4ef6\uff08`nginx -t`\uff09<\/li>\n<li>\u4f7f\u7528 `systemctl reload nginx` \u800c\u975e restart \u91cd\u8f7d\u914d\u7f6e<\/li>\n<li>\u76d1\u63a7\u65e5\u5fd7\u548c\u6027\u80fd\u6307\u6807<\/li>\n<li>\u6839\u636e\u5b9e\u9645\u573a\u666f\u4f18\u5316\u53c2\u6570<\/li>\n<\/ul>\n<p>\u795d\u60a8\u4f7f\u7528\u6109\u5feb\uff01<\/p>\n<p>&#8212;<\/p>\n<p>*\u6587\u6863\u751f\u6210\u65f6\u95f4\uff1a2026 \u5e74 4 \u6708 25 \u65e5*<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx \u8be6\u7ec6\u4f7f\u7528\u6559\u7a0b\uff1a\u4ece\u5165\u95e8\u5230\u7cbe\u901a \u524d\u8a00 Nginx\uff08\u53d1\u97f3\u4e3a &#8220;engine-x&#8221;&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-15908","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts\/15908","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/comments?post=15908"}],"version-history":[{"count":0,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/posts\/15908\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/media?parent=15908"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/categories?post=15908"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.srclibs.com\/index.php\/wp-json\/wp\/v2\/tags?post=15908"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}