{"id":257,"date":"2026-09-17T10:24:06","date_gmt":"2026-09-17T02:24:06","guid":{"rendered":"https:\/\/yykcj.com\/?p=257"},"modified":"2026-09-17T10:24:06","modified_gmt":"2026-09-17T02:24:06","slug":"nginx-%e9%85%8d%e7%bd%ae%e4%bc%98%e5%8c%96%e4%b8%8e%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86%e5%ae%9e%e6%88%98%ef%bc%9a%e4%bb%8e%e5%85%a5%e9%97%a8%e5%88%b0%e9%ab%98%e5%b9%b6%e5%8f%91%e8%b0%83%e4%bc%98","status":"publish","type":"post","link":"https:\/\/yykcj.com\/?p=257","title":{"rendered":"Nginx \u914d\u7f6e\u4f18\u5316\u4e0e\u53cd\u5411\u4ee3\u7406\u5b9e\u6218\uff1a\u4ece\u5165\u95e8\u5230\u9ad8\u5e76\u53d1\u8c03\u4f18"},"content":{"rendered":"<h2>\u4e3a\u4ec0\u4e48\u4f60\u7684 Nginx \u914d\u7f6e\u603b\u662f\u4e0d\u591f\u5feb\uff1f<\/h2>\n<p>\u5f88\u591a\u5f00\u53d1\u8005\u7b2c\u4e00\u6b21\u63a5\u89e6 Nginx \u65f6\uff0c\u5f80\u5f80\u662f\u590d\u5236\u4e00\u6bb5\u201c\u4e07\u80fd\u914d\u7f6e\u201d\u5c31\u4e0a\u7ebf\u4e86\u3002\u7ed3\u679c\u6d41\u91cf\u4e00\u4e0a\u6765\uff0c502\u3001504 \u9891\u7e41\u51fa\u73b0\uff0c\u6216\u8005\u9759\u6001\u8d44\u6e90\u52a0\u8f7d\u7f13\u6162\u3002\u5176\u5b9e Nginx \u7684\u9ed8\u8ba4\u914d\u7f6e\u662f\u4e3a\u901a\u7528\u573a\u666f\u8bbe\u8ba1\u7684\uff0c\u8981\u53d1\u6325\u5b83\u7684\u5a01\u529b\uff0c\u5fc5\u987b\u6839\u636e\u4e1a\u52a1\u7279\u70b9\u8fdb\u884c\u9488\u5bf9\u6027\u8c03\u4f18\u3002<\/p>\n<p>\u672c\u6587\u5c06\u4ee5\u4e00\u4e2a\u5178\u578b\u7684<strong>\u524d\u540e\u7aef\u5206\u79bb\u9879\u76ee<\/strong>\u4e3a\u4f8b\uff1a\u524d\u7aef\u662f Vue \u6253\u5305\u7684\u9759\u6001\u6587\u4ef6\uff0c\u540e\u7aef\u662f\u8fd0\u884c\u5728 8080 \u7aef\u53e3\u7684 Spring Boot \u5e94\u7528\u3002\u6211\u4eec\u5c06\u4ece\u96f6\u5f00\u59cb\u914d\u7f6e Nginx\uff0c\u5b9e\u73b0\u53cd\u5411\u4ee3\u7406\u3001\u8d1f\u8f7d\u5747\u8861\u3001HTTPS\u3001\u7f13\u5b58\u548c\u6027\u80fd\u4f18\u5316\uff0c\u5e76\u5206\u4eab\u4e00\u4e9b\u8e29\u5751\u7ecf\u9a8c\u3002<\/p>\n<h2>\u73af\u5883\u51c6\u5907<\/h2>\n<p>\u5047\u8bbe\u4f60\u6709\u4e00\u53f0 Linux \u670d\u52a1\u5668\uff08Ubuntu 20.04 \u6216 CentOS 7+\uff09\uff0c\u5df2\u7ecf\u5b89\u88c5\u4e86 Nginx\u3002\u5982\u679c\u6ca1\u6709\uff0c\u53ef\u4ee5\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<pre><code class=\"language-bash\">\n# Ubuntu\/Debian\nsudo apt update &amp;&amp; sudo apt install nginx -y\n\n# CentOS\/RHEL\nsudo yum install epel-release -y &amp;&amp; sudo yum install nginx -y\n<\/code><\/pre>\n<p>\u68c0\u67e5\u7248\u672c\uff1a<code>nginx -v<\/code>\uff0c\u5efa\u8bae\u4f7f\u7528 1.18+ \u4ee5\u652f\u6301 HTTP\/2 \u548c\u66f4\u4f18\u7684 TLS \u914d\u7f6e\u3002<\/p>\n<h2>\u7b2c\u4e00\u6b65\uff1a\u57fa\u7840\u53cd\u5411\u4ee3\u7406\u914d\u7f6e<\/h2>\n<p>Nginx \u7684\u6838\u5fc3\u529f\u80fd\u4e4b\u4e00\u5c31\u662f\u53cd\u5411\u4ee3\u7406\u3002\u6211\u4eec\u5148\u914d\u7f6e\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u4ee3\u7406\uff0c\u5c06 <code>\/api\/<\/code> \u8bf7\u6c42\u8f6c\u53d1\u5230\u540e\u7aef\u670d\u52a1\u3002<\/p>\n<p>\u521b\u5efa\u914d\u7f6e\u6587\u4ef6 <code>\/etc\/nginx\/conf.d\/myapp.conf<\/code>\uff1a<\/p>\n<pre><code class=\"language-nginx\">\nserver {\n    listen 80;\n    server_name example.com;\n\n    # \u524d\u7aef\u9759\u6001\u6587\u4ef6\n    location \/ {\n        root \/var\/www\/myapp\/dist;\n        index index.html;\n        try_files $uri $uri\/ \/index.html;  # \u652f\u6301 Vue\/React \u7684 history \u8def\u7531\n    }\n\n    # \u540e\u7aef API \u4ee3\u7406\n    location \/api\/ {\n        proxy_pass http:\/\/127.0.0.1:8080\/;  # \u6ce8\u610f\u672b\u5c3e\u7684\u659c\u6760\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}\n<\/code><\/pre>\n<p><strong>\u5173\u952e\u70b9\u89e3\u6790\uff1a<\/strong><\/p>\n<ul>\n<li><code>proxy<em>pass<\/code> \u672b\u5c3e\u7684\u659c\u6760\uff1a\u5982\u679c <code>location<\/code> \u662f <code>\/api\/<\/code>\uff0c\u800c <code>proxy<\/em>pass<\/code> \u662f <code>http:\/\/127.0.0.1:8080\/<\/code>\uff0c\u90a3\u4e48\u8bf7\u6c42 <code>\/api\/user<\/code> \u4f1a\u88ab\u8f6c\u53d1\u4e3a <code>\/user<\/code>\u3002\u5982\u679c <code>proxy_pass<\/code> \u6ca1\u6709\u672b\u5c3e\u659c\u6760\uff0c\u5219\u4f1a\u8f6c\u53d1\u4e3a <code>\/api\/user<\/code>\u3002\u8fd9\u4e2a\u7ec6\u8282\u6781\u6613\u51fa\u9519\uff0c\u52a1\u5fc5\u6839\u636e\u540e\u7aef\u8def\u7531\u8bbe\u8ba1\u9009\u62e9\u3002<\/li>\n<li><code>try_files<\/code>\uff1a\u5bf9\u4e8e\u5355\u9875\u5e94\u7528\uff0c\u4efb\u4f55\u627e\u4e0d\u5230\u7684\u8def\u5f84\u90fd\u8fd4\u56de <code>index.html<\/code>\uff0c\u7531\u524d\u7aef\u8def\u7531\u5904\u7406\u3002<\/li>\n<li>\u8f6c\u53d1\u5934\u4fe1\u606f\uff1a\u8ba9\u540e\u7aef\u80fd\u83b7\u53d6\u771f\u5b9e\u5ba2\u6237\u7aef IP \u548c\u534f\u8bae\uff0c\u5bf9\u65e5\u5fd7\u548c\u91cd\u5b9a\u5411\u5f88\u91cd\u8981\u3002<\/li>\n<\/ul>\n<p>\u6d4b\u8bd5\u914d\u7f6e\u5e76\u91cd\u8f7d\uff1a<\/p>\n<pre><code class=\"language-bash\">\nsudo nginx -t\nsudo nginx -s reload\n<\/code><\/pre>\n<h2>\u7b2c\u4e8c\u6b65\uff1a\u8d1f\u8f7d\u5747\u8861\u4e0e\u5065\u5eb7\u68c0\u67e5<\/h2>\n<p>\u5f53\u540e\u7aef\u6709\u591a\u53f0\u5b9e\u4f8b\u65f6\uff0c\u53ef\u4ee5\u7528 <code>upstream<\/code> \u505a\u8d1f\u8f7d\u5747\u8861\u3002\u5047\u8bbe\u6709\u4e24\u53f0\u540e\u7aef\u670d\u52a1\u5668\uff1a<\/p>\n<pre><code class=\"language-nginx\">\nupstream backend {\n    least_conn;  # \u6700\u5c11\u8fde\u63a5\u6570\u7b97\u6cd5\uff0c\u9002\u5408\u957f\u8fde\u63a5\u573a\u666f\n    server 192.168.1.10:8080 weight=3 max_fails=2 fail_timeout=30s;\n    server 192.168.1.11:8080 weight=1 max_fails=2 fail_timeout=30s;\n    keepalive 32;  # \u4fdd\u6301\u4e0e\u540e\u7aef\u7684\u957f\u8fde\u63a5\uff0c\u51cf\u5c11\u63e1\u624b\u5f00\u9500\n}\n\nserver {\n    listen 80;\n    server_name example.com;\n\n    location \/api\/ {\n        proxy_pass http:\/\/backend\/;\n        proxy_http_version 1.1;\n        proxy_set_header Connection &quot;&quot;;  # \u914d\u5408 keepalive \u4f7f\u7528\n        # ... \u5176\u4ed6\u5934\u4fe1\u606f\n    }\n}\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li><code>least_conn<\/code> \u6bd4\u9ed8\u8ba4\u7684\u8f6e\u8be2\u66f4\u9002\u5408\u8bf7\u6c42\u5904\u7406\u65f6\u95f4\u4e0d\u5747\u7684\u573a\u666f\u3002<\/li>\n<li><code>weight<\/code> \u53ef\u4ee5\u6839\u636e\u670d\u52a1\u5668\u6027\u80fd\u8c03\u6574\u6743\u91cd\u3002<\/li>\n<li><code>max<em>fails<\/code> \u548c <code>fail<\/em>timeout<\/code> \u5b9e\u73b0\u88ab\u52a8\u5065\u5eb7\u68c0\u67e5\uff1a30 \u79d2\u5185\u5931\u8d25 2 \u6b21\u5219\u6682\u65f6\u5254\u9664\u8be5\u8282\u70b9\u3002<\/li>\n<li><code>keepalive<\/code> \u9700\u8981\u914d\u5408 <code>proxy<em>http<\/em>version 1.1<\/code> \u548c <code>proxy<em>set<\/em>header Connection \"\"<\/code> \u624d\u80fd\u751f\u6548\uff0c\u5426\u5219\u53ef\u80fd\u9002\u5f97\u5176\u53cd\u3002<\/li>\n<\/ul>\n<p>\ud83d\udca1 <strong>\u8fdb\u9636\uff1a<\/strong> \u5982\u679c\u9700\u8981\u4e3b\u52a8\u5065\u5eb7\u68c0\u67e5\uff0c\u53ef\u4ee5\u8003\u8651 Nginx Plus \u6216\u4f7f\u7528 OpenResty \u7684 <code>lua-resty-healthcheck<\/code>\u3002<\/p>\n<h2>\u7b2c\u4e09\u6b65\uff1aHTTPS \u4e0e HTTP\/2 \u914d\u7f6e<\/h2>\n<p>\u5b89\u5168\u662f\u73b0\u4ee3 Web \u7684\u6807\u914d\u3002\u4f7f\u7528 Let&#8217;s Encrypt \u514d\u8d39\u8bc1\u4e66\uff1a<\/p>\n<pre><code class=\"language-bash\">\nsudo apt install certbot python3-certbot-nginx -y\nsudo certbot --nginx -d example.com -d www.example.com\n<\/code><\/pre>\n<p>Certbot \u4f1a\u81ea\u52a8\u4fee\u6539 Nginx \u914d\u7f6e\uff0c\u4f46\u6211\u4eec\u53ef\u4ee5\u624b\u52a8\u4f18\u5316 TLS \u53c2\u6570\uff1a<\/p>\n<pre><code class=\"language-nginx\">\nserver {\n    listen 443 ssl http2;\n    server_name example.com;\n\n    ssl_certificate \/etc\/letsencrypt\/live\/example.com\/fullchain.pem;\n    ssl_certificate_key \/etc\/letsencrypt\/live\/example.com\/privkey.pem;\n\n    # \u73b0\u4ee3 TLS \u914d\u7f6e\n    ssl_protocols TLSv1.2 TLSv1.3;\n    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;\n    ssl_prefer_server_ciphers off;\n\n    # \u4f1a\u8bdd\u590d\u7528\uff0c\u63d0\u5347\u6027\u80fd\n    ssl_session_cache shared:SSL:10m;\n    ssl_session_timeout 1d;\n    ssl_session_tickets off;\n\n    # HSTS (\u8c28\u614e\u5f00\u542f\uff0c\u786e\u4fdd\u6240\u6709\u5b50\u57df\u540d\u90fd\u652f\u6301 HTTPS)\n    add_header Strict-Transport-Security &quot;max-age=63072000&quot; always;\n\n    # ... \u5176\u4ed6 location \u914d\u7f6e\n}\n\n# HTTP \u91cd\u5b9a\u5411\u5230 HTTPS\nserver {\n    listen 80;\n    server_name example.com;\n    return 301 https:\/\/$host$request_uri;\n}\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li><code>ssl<em>prefer<\/em>server_ciphers off<\/code> \u8ba9\u5ba2\u6237\u7aef\u9009\u62e9\u52a0\u5bc6\u5957\u4ef6\uff0c\u901a\u5e38\u66f4\u5feb\uff0c\u56e0\u4e3a\u5ba2\u6237\u7aef\u66f4\u4e86\u89e3\u81ea\u5df1\u7684\u786c\u4ef6\u3002<\/li>\n<li><code>ssl<em>session<\/em>tickets off<\/code> \u63d0\u5347\u524d\u5411\u5b89\u5168\u6027\uff0c\u4f46\u4f1a\u7a0d\u5fae\u589e\u52a0\u63e1\u624b\u5f00\u9500\u3002\u5982\u679c\u8ffd\u6c42\u6027\u80fd\uff0c\u53ef\u4ee5\u5f00\u542f\u3002<\/li>\n<li>HSTS \u5934\u4e00\u65e6\u88ab\u6d4f\u89c8\u5668\u8bb0\u5f55\uff0c\u5728 max-age \u5185\u65e0\u6cd5\u56de\u9000\uff0c\u6d4b\u8bd5\u65f6\u5148\u7528\u5c0f max-age\u3002<\/li>\n<\/ul>\n<h2>\u7b2c\u56db\u6b65\uff1a\u6027\u80fd\u4f18\u5316\u53c2\u6570<\/h2>\n<p>Nginx \u7684\u6027\u80fd\u5f88\u5927\u7a0b\u5ea6\u4e0a\u53d6\u51b3\u4e8e <code>nginx.conf<\/code> \u4e2d\u7684\u5168\u5c40\u914d\u7f6e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u9488\u5bf9\u9ad8\u5e76\u53d1\u7684\u4f18\u5316\u6a21\u677f\uff1a<\/p>\n<pre><code class=\"language-nginx\">\n# \/etc\/nginx\/nginx.conf\nuser www-data;\nworker_processes auto;  # \u81ea\u52a8\u5339\u914d CPU \u6838\u5fc3\u6570\nworker_rlimit_nofile 65535;  # \u6bcf\u4e2a worker \u80fd\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u6570\n\nevents {\n    worker_connections 65535;  # \u6bcf\u4e2a worker \u7684\u6700\u5927\u8fde\u63a5\u6570\n    multi_accept on;  # \u4e00\u6b21\u63a5\u53d7\u6240\u6709\u65b0\u8fde\u63a5\n    use epoll;  # Linux \u4e0b\u9ad8\u6027\u80fd\u4e8b\u4ef6\u6a21\u578b\n}\n\nhttp {\n    # \u57fa\u7840\u4f18\u5316\n    sendfile on;\n    tcp_nopush on;\n    tcp_nodelay on;\n    keepalive_timeout 65;\n    types_hash_max_size 2048;\n    server_tokens off;  # \u9690\u85cf\u7248\u672c\u53f7\n\n    # \u5ba2\u6237\u7aef\u7f13\u5b58\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\n    # \u538b\u7f29\n    gzip on;\n    gzip_vary on;\n    gzip_proxied any;\n    gzip_comp_level 6;\n    gzip_types text\/plain text\/css text\/xml application\/json application\/javascript application\/rss+xml application\/atom+xml image\/svg+xml;\n\n    # \u7f13\u51b2\u533a\n    client_body_buffer_size 10K;\n    client_header_buffer_size 1k;\n    client_max_body_size 8m;\n    large_client_header_buffers 2 1k;\n\n    # \u8d85\u65f6\n    client_body_timeout 12;\n    client_header_timeout 12;\n    send_timeout 10;\n\n    # \u4ee3\u7406\u7f13\u51b2\u533a\n    proxy_buffering on;\n    proxy_buffer_size 4k;\n    proxy_buffers 8 4k;\n    proxy_busy_buffers_size 8k;\n\n    include \/etc\/nginx\/mime.types;\n    default_type application\/octet-stream;\n\n    include \/etc\/nginx\/conf.d\/*.conf;\n    include \/etc\/nginx\/sites-enabled\/*;\n}\n<\/code><\/pre>\n<p><strong>\u53c2\u6570\u89e3\u91ca\uff1a<\/strong><\/p>\n<ul>\n<li><code>worker_processes auto<\/code>\uff1a\u901a\u5e38\u8bbe\u7f6e\u4e3a CPU \u6838\u5fc3\u6570\uff0c\u4f46\u82e5\u78c1\u76d8 I\/O \u5bc6\u96c6\uff0c\u53ef\u4ee5\u9002\u5f53\u589e\u52a0\u3002<\/li>\n<li><code>worker<em>connections<\/code>\uff1a\u7406\u8bba\u6700\u5927\u8fde\u63a5\u6570 = worker<\/em>processes * worker_connections\u3002\u4f46\u53d7\u9650\u4e8e\u7cfb\u7edf\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u9700\u540c\u6b65\u8c03\u6574 <code>ulimit -n<\/code>\u3002<\/li>\n<li><code>multi_accept on<\/code>\uff1a\u8ba9 worker \u4e00\u6b21\u5c3d\u53ef\u80fd\u591a\u5730\u63a5\u53d7\u8fde\u63a5\uff0c\u9ad8\u5e76\u53d1\u4e0b\u6709\u6548\u3002<\/li>\n<li><code>open<em>file<\/em>cache<\/code>\uff1a\u7f13\u5b58\u6587\u4ef6\u63cf\u8ff0\u7b26\uff0c\u51cf\u5c11\u78c1\u76d8 I\/O\uff0c\u5bf9\u9759\u6001\u6587\u4ef6\u670d\u52a1\u63d0\u5347\u660e\u663e\u3002<\/li>\n<li><code>gzip<em>comp<\/em>level 6<\/code>\uff1a\u538b\u7f29\u7ea7\u522b 6 \u662f\u6027\u80fd\u4e0e\u538b\u7f29\u6bd4\u7684\u5e73\u8861\u70b9\uff0c\u518d\u9ad8\u6536\u76ca\u9012\u51cf\u3002<\/li>\n<\/ul>\n<p>\ud83d\udca1 <strong>\u7cfb\u7edf\u5c42\u9762\u4f18\u5316\uff1a<\/strong> \u4fee\u6539 <code>\/etc\/security\/limits.conf<\/code> \u589e\u52a0 <code>nofile<\/code>\uff0c\u8c03\u6574\u5185\u6838\u53c2\u6570\u5982 <code>net.core.somaxconn<\/code>\u3001<code>net.ipv4.tcp<em>tw<\/em>reuse<\/code> \u7b49\u3002<\/p>\n<h2>\u7b2c\u4e94\u6b65\uff1a\u9759\u6001\u8d44\u6e90\u7f13\u5b58\u4e0e CDN \u914d\u5408<\/h2>\n<p>\u5bf9\u4e8e\u524d\u7aef\u9759\u6001\u8d44\u6e90\uff0c\u5229\u7528\u6d4f\u89c8\u5668\u7f13\u5b58\u80fd\u5927\u5e45\u51cf\u5c11\u8bf7\u6c42\u3002\u5728 <code>location<\/code> \u4e2d\u4e3a\u5e26\u54c8\u5e0c\u7684\u6587\u4ef6\u8bbe\u7f6e\u957f\u671f\u7f13\u5b58\uff1a<\/p>\n<pre><code class=\"language-nginx\">\nlocation ~* \\.(js|css|png|jpg|jpeg|gif|ico|svg|woff2?)$ {\n    root \/var\/www\/myapp\/dist;\n    expires 1y;\n    add_header Cache-Control &quot;public, immutable&quot;;\n    access_log off;\n}\n\nlocation = \/index.html {\n    root \/var\/www\/myapp\/dist;\n    add_header Cache-Control &quot;no-cache, no-store, must-revalidate&quot;;\n}\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u53ea\u6709\u6587\u4ef6\u540d\u5305\u542b\u54c8\u5e0c\uff08\u5982 <code>app.abc123.js<\/code>\uff09\u624d\u80fd\u8bbe\u7f6e\u957f\u671f\u7f13\u5b58\uff0c\u5426\u5219\u66f4\u65b0\u540e\u5ba2\u6237\u7aef\u65e0\u6cd5\u83b7\u53d6\u65b0\u7248\u672c\u3002<\/li>\n<li><code>index.html<\/code> \u5fc5\u987b\u7981\u7528\u7f13\u5b58\uff0c\u5426\u5219\u7528\u6237\u53ef\u80fd\u4e00\u76f4\u4f7f\u7528\u65e7\u7248\u672c\u3002<\/li>\n<li>\u5982\u679c\u4f7f\u7528 CDN\uff0c\u53ef\u4ee5\u5728 CDN \u56de\u6e90\u65f6\u8bbe\u7f6e\u7f13\u5b58\u89c4\u5219\uff0cNginx \u5c42\u53ef\u4ee5\u7b80\u5316\u3002<\/li>\n<\/ul>\n<h2>\u5e38\u89c1\u5751\u4e0e\u6392\u67e5\u6280\u5de7<\/h2>\n<ol>\n<li><strong>502 Bad Gateway<\/strong>\uff1a\u901a\u5e38\u662f\u540e\u7aef\u670d\u52a1\u672a\u542f\u52a8\u6216\u7aef\u53e3\u4e0d\u5bf9\u3002\u68c0\u67e5 <code>proxy_pass<\/code> \u5730\u5740\uff0c\u67e5\u770b\u540e\u7aef\u65e5\u5fd7\u3002<\/li>\n<li><strong>504 Gateway Timeout<\/strong>\uff1a\u540e\u7aef\u5904\u7406\u8d85\u65f6\u3002\u8c03\u6574 <code>proxy<em>read<\/em>timeout<\/code>\uff08\u9ed8\u8ba4 60s\uff09\uff0c\u4f46\u66f4\u5e94\u4f18\u5316\u540e\u7aef\u6027\u80fd\u3002<\/li>\n<li><strong>413 Request Entity Too Large<\/strong>\uff1a\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u9650\u5236\u3002\u8c03\u6574 <code>client<em>max<\/em>body_size<\/code>\u3002<\/li>\n<li><strong>\u9759\u6001\u8d44\u6e90 404<\/strong>\uff1a\u68c0\u67e5 <code>root<\/code> \u8def\u5f84\u662f\u5426\u6b63\u786e\uff0c\u6743\u9650\u662f\u5426\u8db3\u591f\uff08Nginx \u7528\u6237\u9700\u6709\u8bfb\u6743\u9650\uff09\u3002<\/li>\n<li><strong>WebSocket \u4ee3\u7406\u5931\u8d25<\/strong>\uff1a\u9700\u8981\u989d\u5916\u914d\u7f6e\uff1a<\/li>\n<\/ol>\n<p>&#8220;<code>nginx proxy<em>set<\/em>header Upgrade $http<em>upgrade; proxy<\/em>set_header Connection \"upgrade\"; <\/code>&#8220;<\/p>\n<ol>\n<li><strong>\u8de8\u57df\u95ee\u9898<\/strong>\uff1a\u53ef\u4ee5\u5728 Nginx \u5c42\u6dfb\u52a0 CORS \u5934\uff0c\u4f46\u6ce8\u610f\u4e0d\u8981\u4e0e\u540e\u7aef\u91cd\u590d\u3002<\/li>\n<\/ol>\n<p><strong>\u8c03\u8bd5\u5229\u5668\uff1a<\/strong><\/p>\n<ul>\n<li><code>nginx -t<\/code> \u6d4b\u8bd5\u914d\u7f6e\u8bed\u6cd5\u3002<\/li>\n<li><code>tail -f \/var\/log\/nginx\/error.log<\/code> \u5b9e\u65f6\u67e5\u770b\u9519\u8bef\u3002<\/li>\n<li><code>curl -I -H \"Host: example.com\" http:\/\/127.0.0.1<\/code> \u6a21\u62df\u8bf7\u6c42\u3002<\/li>\n<li>\u4f7f\u7528 <code>nginx -T<\/code> \u8f93\u51fa\u6700\u7ec8\u751f\u6548\u7684\u5b8c\u6574\u914d\u7f6e\uff0c\u6392\u67e5 include \u51b2\u7a81\u3002<\/li>\n<\/ul>\n<h2>\u603b\u7ed3\u4e0e\u4e0b\u4e00\u6b65<\/h2>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u4e94\u6b65\uff0c\u4f60\u5df2\u7ecf\u62e5\u6709\u4e86\u4e00\u4e2a\u652f\u6301\u53cd\u5411\u4ee3\u7406\u3001\u8d1f\u8f7d\u5747\u8861\u3001HTTPS\u3001\u7f13\u5b58\u548c\u9ad8\u5e76\u53d1\u4f18\u5316\u7684 Nginx \u914d\u7f6e\u3002\u8bb0\u4f4f\uff0c\u6ca1\u6709\u201c\u4e07\u80fd\u914d\u7f6e\u201d\uff0c\u4e00\u5b9a\u8981\u6839\u636e\u5b9e\u9645\u4e1a\u52a1\u538b\u6d4b\u540e\u8c03\u6574\u53c2\u6570\u3002<\/p>\n<p><strong>\u5ef6\u4f38\u65b9\u5411\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528 OpenResty \u548c Lua \u5b9e\u73b0\u52a8\u6001\u9650\u6d41\u3001\u9274\u6743\u3002<\/li>\n<li>\u914d\u7f6e Nginx \u4f5c\u4e3a API \u7f51\u5173\uff0c\u96c6\u6210 JWT \u9a8c\u8bc1\u3002<\/li>\n<li>\u7ed3\u5408 Prometheus + Grafana \u76d1\u63a7 Nginx \u6307\u6807\uff08\u9700 <code>nginx-module-vts<\/code>\uff09\u3002<\/li>\n<li>\u5b66\u4e60 <code>map<\/code> \u6307\u4ee4\u5b9e\u73b0\u66f4\u7075\u6d3b\u7684\u6761\u4ef6\u5224\u65ad\u3002<\/li>\n<\/ul>\n<p>\u5e0c\u671b\u672c\u6587\u80fd\u5e2e\u4f60\u5c11\u8d70\u5f2f\u8def\uff0c\u6784\u5efa\u66f4\u7a33\u5b9a\u7684 Web \u670d\u52a1\u3002\u5982\u679c\u6709\u95ee\u9898\uff0c\u6b22\u8fce\u5728\u8bc4\u8bba\u533a\u4ea4\u6d41\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u901a\u8fc7\u4e00\u4e2a\u771f\u5b9e\u7684\u524d\u540e\u7aef\u5206\u79bb\u9879\u76ee\uff0c\u624b\u628a\u624b\u6559\u4f60\u914d\u7f6e Nginx \u53cd\u5411\u4ee3\u7406\u3001\u8d1f\u8f7d\u5747\u8861\u3001HTTPS \u548c\u6027\u80fd\u4f18\u5316\u53c2\u6570\u3002\u6db5\u76d6\u5e38\u89c1\u5751\u70b9\u4e0e\u6700\u4f73\u5b9e\u8df5\uff0c\u52a9\u4f60\u6784\u5efa\u9ad8\u53ef\u7528\u3001\u9ad8\u6027\u80fd\u7684 Web \u670d\u52a1\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[235,232,233,6,234],"class_list":["post-257","post","type-post","status-publish","format-standard","hentry","category-3","category-4","tag-https","tag-nginx","tag-233","tag-6","tag-234"],"_links":{"self":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=257"}],"version-history":[{"count":0,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/257\/revisions"}],"wp:attachment":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}