{"id":464,"date":"2023-07-05T13:04:24","date_gmt":"2023-07-05T05:04:24","guid":{"rendered":"https:\/\/www.wangzheduo.com\/?p=464"},"modified":"2023-07-05T13:04:24","modified_gmt":"2023-07-05T05:04:24","slug":"nginx%e8%bd%ac%e5%8f%91%e5%ae%b9%e5%99%a8%e9%87%8c%e7%9a%84%e7%bd%91%e7%ab%99-%e5%ae%89%e8%a3%85nginx-%e9%87%8d%e8%bd%bdnginx","status":"publish","type":"post","link":"http:\/\/www.wangzheduo.com\/?p=464","title":{"rendered":"NGINX\u8f6c\u53d1\u5bb9\u5668\u91cc\u7684\u7f51\u7ad9 \u5b89\u88c5NGINX \u91cd\u8f7dNGINX"},"content":{"rendered":"<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">server {\r\n        listen 80;\r\n        server_name laohu2.linux724.com;\r\n\r\n        location \/ {\r\n            proxy_pass http:\/\/localhost:8880;\r\n            proxy_set_header Host $host;\r\n            proxy_set_header X-Real-IP $remote_addr;\r\n            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\r\n        }\r\n    }<\/pre>\n<p>\u8981\u5728 VPS \u4e0a\u5b89\u88c5 Nginx\uff0c\u60a8\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\uff1a<\/p>\n<ol>\n<li>\u767b\u5f55\u5230\u60a8\u7684 VPS\uff1a \u4f7f\u7528 SSH \u5ba2\u6237\u7aef\u8fde\u63a5\u5230\u60a8\u7684 VPS\uff0c\u5e76\u4f7f\u7528\u7ba1\u7406\u5458\u6216\u5177\u6709\u8db3\u591f\u6743\u9650\u7684\u7528\u6237\u767b\u5f55\u3002<\/li>\n<li>\u66f4\u65b0\u7cfb\u7edf\uff1a \u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u66f4\u65b0\u64cd\u4f5c\u7cfb\u7edf\u7684\u8f6f\u4ef6\u5305\u5217\u8868\u548c\u5df2\u5b89\u88c5\u8f6f\u4ef6\u5305\uff1a\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-sql\">sudo apt <span class=\"hljs-keyword\">update<\/span><br \/>\nsudo apt upgrade<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<li>\u5b89\u88c5 Nginx\uff1a \u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5 Nginx\uff1a\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs\">sudo apt install nginx<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<li>\u542f\u52a8 Nginx \u670d\u52a1\uff1a \u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8 Nginx \u670d\u52a1\uff1a\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-sql\">sudo systemctl <span class=\"hljs-keyword\">start<\/span> nginx<br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<li>\u9a8c\u8bc1\u5b89\u88c5\uff1a \u6253\u5f00\u60a8\u7684 web \u6d4f\u89c8\u5668\uff0c\u5e76\u8bbf\u95ee\u60a8\u7684 VPS \u7684\u516c\u5171 IP \u5730\u5740\u6216\u57df\u540d\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u5e94\u8be5\u80fd\u591f\u770b\u5230 Nginx \u7684\u6b22\u8fce\u9875\u9762\u3002\n<p>\u6ce8\u610f\uff1a\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cNginx \u7684\u914d\u7f6e\u6587\u4ef6\u5b58\u50a8\u5728 <code>\/etc\/nginx<\/code> \u76ee\u5f55\u4e0b\uff0c\u7f51\u7ad9\u6587\u4ef6\u5b58\u50a8\u5728 <code>\/var\/www\/html<\/code> \u76ee\u5f55\u4e0b\u3002\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u914d\u7f6e\u548c\u81ea\u5b9a\u4e49\u3002<\/li>\n<li>\u914d\u7f6e\u9632\u706b\u5899\uff08\u53ef\u9009\uff09\uff1a \u5982\u679c\u60a8\u7684 VPS \u4e0a\u542f\u7528\u4e86\u9632\u706b\u5899\uff0c\u60a8\u9700\u8981\u5141\u8bb8 HTTP\uff0880\uff09\u548c HTTPS\uff08443\uff09\u7aef\u53e3\u7684\u4f20\u5165\u8fde\u63a5\u3002\u5177\u4f53\u7684\u914d\u7f6e\u65b9\u6cd5\u53d6\u51b3\u4e8e\u60a8\u4f7f\u7528\u7684\u9632\u706b\u5899\u8f6f\u4ef6\uff0c\u5e38\u89c1\u7684\u6709 UFW\u3001iptables \u7b49\u3002\n<p>\u4f8b\u5982\uff0c\u4f7f\u7528 UFW \u914d\u7f6e\u9632\u706b\u5899\u5141\u8bb8 HTTP \u548c HTTPS \u6d41\u91cf\uff1a<\/p>\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs language-bash\">sudo ufw allow <span class=\"hljs-string\">'Nginx HTTP'<\/span><br \/>\nsudo ufw allow <span class=\"hljs-string\">'Nginx HTTPS'<\/span><br \/>\nsudo ufw <span class=\"hljs-built_in\">enable<\/span><br \/>\n<\/code><\/div>\n<\/div>\n<\/li>\n<\/ol>\n<p>\u73b0\u5728\uff0c\u60a8\u5df2\u7ecf\u6210\u529f\u5728 VPS \u4e0a\u5b89\u88c5\u4e86 Nginx\u3002\u60a8\u53ef\u4ee5\u6839\u636e\u9700\u8981\u914d\u7f6e Nginx\uff0c\u6dfb\u52a0\u548c\u7ba1\u7406\u7f51\u7ad9\u3001\u865a\u62df\u4e3b\u673a\u7b49\u3002\u8bf7\u53c2\u8003 Nginx \u7684\u5b98\u65b9\u6587\u6863\u4ee5\u4e86\u89e3\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\u548c\u914d\u7f6e\u9009\u9879\u3002<\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c\u4e0a\u8ff0\u6b65\u9aa4\u662f\u57fa\u4e8e Debian \u6216 Ubuntu \u7cfb\u7edf\u7684\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f\u5176\u4ed6 Linux \u53d1\u884c\u7248\u6216\u64cd\u4f5c\u7cfb\u7edf\uff0c\u8bf7\u6839\u636e\u76f8\u5e94\u7684\u5305\u7ba1\u7406\u5668\u548c\u7cfb\u7edf\u89c4\u8303\u8fdb\u884c\u76f8\u5e94\u7684\u8c03\u6574\u3002<\/p>\n<p>&nbsp;<\/p>\n<ol>\n<li>\u68c0\u67e5\u914d\u7f6e\u6587\u4ef6\u8bed\u6cd5\u662f\u5426\u6b63\u786e\uff1a \u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5 Nginx \u914d\u7f6e\u6587\u4ef6\u7684\u8bed\u6cd5\u662f\u5426\u6b63\u786e\uff1a\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs\">sudo nginx -t<br \/>\n<\/code><\/div>\n<\/div>\n<p>\u5982\u679c\u6ca1\u6709\u9519\u8bef\u63d0\u793a\uff0c\u5219\u8868\u793a\u914d\u7f6e\u6587\u4ef6\u8bed\u6cd5\u6b63\u786e\u3002<\/li>\n<li>\u91cd\u542f Nginx \u670d\u52a1\uff1a \u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u91cd\u542f Nginx \u670d\u52a1\u4f7f\u914d\u7f6e\u751f\u6548\uff1a\n<div class=\"bg-black rounded-md mb-4\">\n<div class=\"flex items-center relative text-gray-200 bg-gray-800 px-4 py-2 text-xs font-sans justify-between rounded-t-md\"><\/div>\n<div class=\"p-4 overflow-y-auto\"><code class=\"!whitespace-pre hljs\">sudo systemctl restart nginx<\/code><\/div>\n<\/div>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>server { listen 80; server_name laohu2.linux724.com; location \/ { proxy_pass http:\/\/localhost:8880; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-464","post","type-post","status-publish","format-standard","hentry","category-nginx"],"_links":{"self":[{"href":"http:\/\/www.wangzheduo.com\/index.php?rest_route=\/wp\/v2\/posts\/464","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.wangzheduo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.wangzheduo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.wangzheduo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.wangzheduo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=464"}],"version-history":[{"count":1,"href":"http:\/\/www.wangzheduo.com\/index.php?rest_route=\/wp\/v2\/posts\/464\/revisions"}],"predecessor-version":[{"id":465,"href":"http:\/\/www.wangzheduo.com\/index.php?rest_route=\/wp\/v2\/posts\/464\/revisions\/465"}],"wp:attachment":[{"href":"http:\/\/www.wangzheduo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=464"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.wangzheduo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=464"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.wangzheduo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=464"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}