{"id":17324,"date":"2024-11-18T16:20:17","date_gmt":"2024-11-18T08:20:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/17324\/"},"modified":"2024-11-18T16:20:17","modified_gmt":"2024-11-18T08:20:17","slug":"nginx%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0http%e4%bb%a3%e7%90%86%e9%85%8d%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/17324\/","title":{"rendered":"Nginx\u5982\u4f55\u5b9e\u73b0HTTP\u4ee3\u7406\u914d\u7f6e"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/169942711357208.jpg\" class=\"aligncenter\" title=\"Nginx\u5982\u4f55\u5b9e\u73b0HTTP\u4ee3\u7406\u914d\u7f6e\u63d2\u56fe\" alt=\"Nginx\u5982\u4f55\u5b9e\u73b0HTTP\u4ee3\u7406\u914d\u7f6e\u63d2\u56fe\" \/><\/p>\n<p>Nginx\u662f\u4e00\u79cd\u9ad8\u6027\u80fd\u7684\u5f00\u6e90Web\u670d\u52a1\u5668\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u548c\u8d1f\u8f7d\u5747\u8861\u5668\u3002\u5b83\u7684\u7075\u6d3b\u6027\u548c\u5f3a\u5927\u7684\u529f\u80fd\u4f7f\u5f97\u5b83\u6210\u4e3a\u4e86\u8bb8\u591a\u7f51\u7ad9\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u9996\u9009\uff0c\u4e5f\u56e0\u6b64\uff0c\u5bf9\u4e8e\u5f88\u591a\u670d\u52a1\u5668\u7ba1\u7406\u5458\u6765\u8bf4\uff0cNginx\u7684HTTP\u4ee3\u7406\u914d\u7f6e\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u77e5\u8bc6\u70b9\u3002<\/p>\n<p>\u5728Nginx\u4e2d\uff0c\u5b9e\u73b0HTTP\u4ee3\u7406\u914d\u7f6e\u4e00\u822c\u9700\u8981\u901a\u8fc7\u4fee\u6539Nginx\u7684\u914d\u7f6e\u6587\u4ef6\u6765\u5b8c\u6210\u3002\u4e0b\u9762\u6211\u4eec\u5c31\u6765\u5177\u4f53\u4e86\u89e3\u4e00\u4e0bNginx\u5982\u4f55\u5b9e\u73b0HTTP\u4ee3\u7406\u914d\u7f6e\uff0c\u5e76\u9644\u4e0a\u4e00\u4e9b\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<p><strong>\u6b65\u9aa4\u4e00\uff1a\u5b89\u88c5Nginx<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Nginx\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<pre># Ubuntu\nsudo apt-get install nginx\n\n# CentOS\nsudo yum install nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4\u4e8c\uff1a\u6dfb\u52a0HTTP\u4ee3\u7406\u914d\u7f6e<\/strong><\/p>\n<p>\u6253\u5f00Nginx\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4e00\u822c\u4f4d\u4e8e\/etc\/\/nginx.conf\u6216\/etc\/nginx\/conf.d\/default.conf\uff0c\u7136\u540e\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre>server {\n    listen 80;\n    server_name your_domain.com;\n\n    location \/ {\n        proxy_pass http:\/\/your_backend_server;\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    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u914d\u7f6e\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528location\u6307\u4ee4\u5b9a\u4e49\u4e86HTTP\u4ee3\u7406\u7684\u4f4d\u7f6e\uff0cproxy_pass\u6307\u4ee4\u6307\u5b9a\u4e86\u9700\u8981\u4ee3\u7406\u5230\u7684\u540e\u7aef\u670d\u52a1\u5668\u5730\u5740\uff0cproxy_set_header\u6307\u4ee4\u8bbe\u7f6e\u4e86\u4e00\u4e9bHTTP\u5934\u4fe1\u606f\uff0c\u5982Host\u3001X-Real-IP\u548cX-Forwarded-For\u3002<\/p>\n<p><strong>\u6b65\u9aa4\u4e09\uff1a\u91cd\u65b0\u52a0\u8f7dNginx\u914d\u7f6e<\/strong><\/p>\n<p>\u5f53\u6dfb\u52a0\u6216\u4fee\u6539\u4e86HTTP\u4ee3\u7406\u914d\u7f6e\u540e\uff0c\u9700\u8981\u91cd\u65b0\u52a0\u8f7dNginx\u7684\u914d\u7f6e\u6587\u4ef6\u4ee5\u4f7f\u914d\u7f6e\u751f\u6548\uff1a<\/p>\n<pre>sudo nginx -s reload<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4\u56db\uff1a\u6d4b\u8bd5HTTP\u4ee3\u7406<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u901a\u8fc7\u6d4f\u89c8\u5668\u6216\u8005curl\u547d\u4ee4\u6d4b\u8bd5HTTP\u4ee3\u7406\u662f\u5426\u751f\u6548\uff1a<\/p>\n<pre>curl -i http:\/\/your_domain.com<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u662f\u4e00\u4e2a\u7b80\u5355\u7684Nginx HTTP\u4ee3\u7406\u914d\u7f6e\u793a\u4f8b\uff0c\u9700\u8981\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u4fee\u6539 server_name \u548c proxy_pass \u90e8\u5206\u3002\u5f53\u7136\uff0c\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u80fd\u8fd8\u9700\u8981\u8003\u8651\u8d1f\u8f7d\u5747\u8861\u3001\u7f13\u5b58\u3001\u65e5\u5fd7\u8bb0\u5f55\u7b49\u66f4\u591a\u7684\u914d\u7f6e\u7ec6\u8282\u3002\u603b\u7684\u6765\u8bf4\uff0cNginx\u63d0\u4f9b\u4e86\u975e\u5e38\u7075\u6d3b\u548c\u5f3a\u5927\u7684HTTP\u4ee3\u7406\u529f\u80fd\uff0c\u80fd\u591f\u6ee1\u8db3\u5927\u591a\u6570\u573a\u666f\u7684\u9700\u6c42\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fNginx\u5982\u4f55\u5b9e\u73b0HTTP\u4ee3\u7406\u914d\u7f6e\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Nginx\u662f\u4e00\u79cd\u9ad8\u6027\u80fd\u7684\u5f00\u6e90Web\u670d\u52a1\u5668\uff0c\u540c\u65f6\u4e5f\u53ef\u4ee5\u4f5c\u4e3a\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u548c\u8d1f\u8f7d\u5747\u8861\u5668\u3002\u5b83\u7684\u7075\u6d3b\u6027\u548c\u5f3a\u5927\u7684\u529f\u80fd\u4f7f\u5f97\u5b83\u6210\u4e3a\u4e86\u8bb8\u591a\u7f51\u7ad9\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u9996\u9009\uff0c\u4e5f\u56e0\u6b64\uff0c\u5bf9\u4e8e\u5f88\u591a\u670d\u52a1\u5668\u7ba1\u7406\u5458\u6765\u8bf4\uff0cNginx\u7684HTTP\u4ee3\u7406\u914d\u7f6e\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u77e5\u8bc6\u70b9\u3002 \u5728Nginx\u4e2d\uff0c\u5b9e\u73b0HTTP\u4ee3\u7406\u914d\u7f6e\u4e00\u822c\u9700\u8981\u901a\u8fc7\u4fee\u6539Nginx\u7684\u914d\u7f6e\u6587\u4ef6\u6765\u5b8c\u6210\u3002\u4e0b\u9762\u6211\u4eec\u5c31\u6765\u5177\u4f53\u4e86\u89e3\u4e00\u4e0bNginx\u5982\u4f55\u5b9e\u73b0HTTP\u4ee3\u7406\u914d\u7f6e\uff0c\u5e76\u9644\u4e0a\u4e00\u4e9b\u4ee3\u7801\u793a\u4f8b\u3002 \u6b65\u9aa4\u4e00\uff1a\u5b89\u88c5Nginx \u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86Nginx\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u8fdb\u884c\u5b89\u88c5\uff1a # Ubuntu sudo apt-get install nginx # CentOS sudo yum install nginx \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4\u4e8c\uff1a\u6dfb\u52a0HTTP\u4ee3\u7406\u914d\u7f6e \u6253\u5f00Nginx\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4e00\u822c\u4f4d\u4e8e\/etc\/\/nginx.conf\u6216\/etc\/nginx\/conf.d\/default.conf\uff0c\u7136\u540e\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a server { listen 80; server_name your_domain.com; location \/ { proxy_pass http:\/\/your_backend_server; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u4e2a\u914d\u7f6e\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528location\u6307\u4ee4\u5b9a\u4e49\u4e86HTTP\u4ee3\u7406\u7684\u4f4d\u7f6e\uff0cproxy_pass\u6307\u4ee4\u6307\u5b9a\u4e86\u9700\u8981\u4ee3\u7406\u5230\u7684\u540e\u7aef\u670d\u52a1\u5668\u5730\u5740\uff0cproxy_set_header\u6307\u4ee4\u8bbe\u7f6e\u4e86\u4e00\u4e9bHTTP\u5934\u4fe1\u606f\uff0c\u5982Host\u3001X-Real-IP\u548cX-Forwarded-For\u3002 \u6b65\u9aa4\u4e09\uff1a\u91cd\u65b0\u52a0\u8f7dNginx\u914d\u7f6e \u5f53\u6dfb\u52a0\u6216\u4fee\u6539\u4e86HTTP\u4ee3\u7406\u914d\u7f6e\u540e\uff0c\u9700\u8981\u91cd\u65b0\u52a0\u8f7dNginx\u7684\u914d\u7f6e\u6587\u4ef6\u4ee5\u4f7f\u914d\u7f6e\u751f\u6548\uff1a sudo nginx -s reload \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4\u56db\uff1a\u6d4b\u8bd5HTTP\u4ee3\u7406 \u6700\u540e\uff0c\u901a\u8fc7\u6d4f\u89c8\u5668\u6216\u8005curl\u547d\u4ee4\u6d4b\u8bd5HTTP\u4ee3\u7406\u662f\u5426\u751f\u6548\uff1a curl -i http:\/\/your_domain.com [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-17324","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17324","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=17324"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17324\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=17324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=17324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=17324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}