{"id":253958,"date":"2022-10-01T09:01:13","date_gmt":"2022-10-01T01:01:13","guid":{"rendered":"https:\/\/gulass.cn\/?p=253958"},"modified":"2022-09-28T11:01:43","modified_gmt":"2022-09-28T03:01:43","slug":"nginx-how-linux","status":"publish","type":"post","link":"https:\/\/gulass.cn\/nginx-how-linux.html","title":{"rendered":"Nginx\u5982\u4f55\u914d\u7f6e\u591a\u4e2a\u670d\u52a1\u57df\u540d\u89e3\u6790\u5171\u752880\u7aef\u53e3"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5bf9\u4e8eWeb\u800c\u5df2,80\u7aef\u53e3\u548c443\u7aef\u53e3\u662f\u5341\u5206\u91cd\u8981\u7684,\u4e0b\u9762\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u4e86\u5173\u4e8eNginx\u5982\u4f55\u914d\u7f6e\u591a\u4e2a\u670d\u52a1\u57df\u540d\u89e3\u6790\u5171\u752880\u7aef\u53e3\u7684\u76f8\u5173\u8d44\u6599,\u6587\u4e2d\u901a\u8fc7\u5b9e\u4f8b\u4ee3\u7801\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u524d\u8a00<\/strong><\/div>\n

\u7531\u4e8e\u516c\u53f8\u4e00\u53f0\u670d\u52a1\u5668\u540c\u65f6\u6709\u591a\u4e2a\u670d\u52a1\uff0c\u8fd9\u4e9b\u670d\u52a1\u901a\u8fc7\u57df\u540d\u89e3\u6790\u90fd\u5e0c\u671b\u76d1\u542c80\/443\u7aef\u53e3\u76f4\u63a5\u901a\u8fc7\u57df\u540d\u8bbf\u95ee\uff0c\u6bd4\u5982\u6709demo.test.com\u548cproduct.test.com\u3002\u8fd9\u65f6\u5019\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528nginx\u7684\u4ee3\u7406\u8f6c\u53d1\u529f\u80fd\u5e2e\u6211\u4eec\u5b9e\u73b0\u5171\u752880\/443\u7aef\u53e3\u7684\u9700\u6c42\u3002<\/p>\n

\u5907\u6ce8\uff1a\u7531\u4e8eHTTP\u534f\u8bae\u9ed8\u8ba4\u76d1\u542c80\u7aef\u53e3\uff0cHTTPS\u534f\u8bae\u9ed8\u8ba4\u76d1\u542c443\u7aef\u53e3\uff0c\u6240\u4ee5\u4f7f\u7528\u6d4f\u89c8\u5668\u8bbf\u95ee80\/443\u7aef\u53e3\u7684\u670d\u52a1\u65f6\uff0c\u53ef\u4ee5\u5ffd\u7565\u57df\u540d\u540e\u7684\u201c :80\/:443\u201d \u7aef\u53e3\uff0c\u76f4\u63a5\u914d\u7f6e\u76d1\u542c\u523080\u7aef\u53e3\uff0c\u8bbf\u95ee\u6bd4\u8f83\u65b9\u4fbf\u3002<\/p>\n

\u914d\u7f6enginx\u591a\u670d\u52a1\u5171\u752880\u7aef\u53e3<\/strong><\/div>\n

\u9996\u5148\u627e\u5230nginx\u914d\u7f6e\u6587\u4ef6 <\/p>\n

\u901a\u8fc7apt-get install nginx\u547d\u4ee4\u5b89\u88c5\u7684nginx\u9ed8\u8ba4\u914d\u7f6e\u6587\u4ef6\u5b58\u653e\u5728\uff1a\/etc\/nginx\u76ee\u5f55\u4e0b\r\n  \r\n\u5207\u6362\u5230\/etc\/nginx\u76ee\u5f55\r\n  \r\n#cd \/etc\/nginx           #\u5207\u6362\u5230nginx\u76ee\u5f55\r\n  \r\n# ls                     #\u67e5\u770bnginx\u76ee\u5f55\u4e0b\u6587\u4ef6\r\nconf.d        fastcgi_params  koi-win     modules-available  nginx.conf    scgi_params      sites-enabled  uwsgi_params fastcgi.conf  koi-utf         mime.types  modules-enabled    proxy_params  sites-available  snippets       win-utf\r\n  \r\n#vim nginx.conf          #\u6253\u5f00nginx\u914d\u7f6e\u6587\u4ef6\uff08\u8f93\u5165shift+i\u63d2\u5165\u5185\u5bb9\uff0cesc\u9000\u51fa\u7f16\u8f91\uff0c\u70b9\u51fbshift+\uff1a\u8f93\u5165q\u9000\u51fa\u5f53\u524d\u9875\uff0cq\uff01\u5f3a\u5236\u9000\u51fa\uff0c\u4e0d\u4fdd\u5b58\u7f16\u8f91\u7684\u5185\u5bb9\uff1b\u8f93\u5165wq\uff01\u5f3a\u5236\u9000\u51fa\u5e76\u4fdd\u5b58\uff09<\/pre>\n
\u4ee5\u4e0b\u4ee5\u4e24\u4e2a\u670d\u52a1\u4f7f\u7528\u57df\u540d\u8bbf\u95ee\uff0c\u5171\u752880\u7aef\u53e3\u4e3a\u4f8b<\/strong><\/div>\n
\u65b9\u6848\u4e00\uff1a\u591a\u4e2a\u4e0d\u540c\u7aef\u53e3\u670d\u52a1\u5171\u752880\u7aef\u53e3<\/strong><\/span><\/div>\n

1\uff09\u914d\u7f6enginx.conf\u6587\u4ef6<\/p>\n

1.\u5148\u914d\u7f6e\u4e24\u4e2a\u7aef\u53e3\u670d\u52a1\uff1a\r\n\/\/ nginx.conf\r\n#demo\r\nserver {\r\n    listen       8001;\r\n    server_name localhost;\r\n    try_files $uri $uri\/ \/index.html;\r\n    root    \/home\/www\/demo;\r\n}\r\n#product\r\nserver {\r\n    listen        8002;\r\n    server_name  localhost;\r\n    try_files $uri $uri\/ \/index.html;\r\n    root    \/home\/www\/product;\r\n}\r\n  \r\n2.\u914d\u7f6e\u4ee3\u7406\uff1a\r\n\/\/ nginx.conf\r\n#demo\u8f6c\u53d1\r\nserver {\r\n    listen       80;\r\n    server_name demo.test.com;\r\n    location \/ {\r\n        proxy_pass http:\/\/localhost:8001;\r\n    }\r\n}\r\n#product\u8f6c\u53d1\r\nserver {\r\n    listen       80;\r\n    server_name product.test.com;\r\n    location \/ {\r\n        proxy_pass http:\/\/localhost:8002;\r\n    }\r\n}<\/pre>\n

2\uff09\u914d\u7f6e\u5b8c\u6210\u540e\u91cd\u542fnginx\u670d\u52a1<\/p>\n

#systemctl restart nginx<\/pre>\n

3) \u5982\u679c\u662f\u672c\u5730\u5c40\u57df\u7f51\u9700\u8981\u914d\u7f6e\u7f51\u7edc\u5c06\u5bf9\u5e94\u7684\u7aef\u53e3\uff0c\u6211\u8fd9\u8fb9\u662f80\uff0c8001\uff0c8002\u4e09\u4e2a\u7aef\u53e3\u6620\u5c04\u5230\u516c\u7f51IP\uff0c\u5e76\u89e3\u6790\u5bf9\u5e94\u7684\u57df\u540d\uff0c\u5b8c\u6210\u540e\u5c31\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\u4e86\uff1b<\/p>\n

\u65b9\u6848\u4e8c\uff1a\u591a\u4e2a\u670d\u52a1\u5171\u752880\u7aef\u53e3<\/strong><\/span><\/div>\n

1\uff09\u914d\u7f6enginx.conf\u6587\u4ef6<\/p>\n

\/\/ nginx.conf\r\n# nginx 80\u7aef\u53e3\u914d\u7f6e \uff08\u76d1\u542cdemo\u4e8c\u7ea7\u57df\u540d\uff09\r\nserver {\r\n    listen  80;\r\n    server_name     demo.test.com;\r\n    location \/ {\r\n        root   \/home\/www\/demo;\r\n        index  index.html index.htm;\r\n    }\r\n}\r\n  \r\n# nginx 80\u7aef\u53e3\u914d\u7f6e \uff08\u76d1\u542cproduct\u4e8c\u7ea7\u57df\u540d\uff09\r\nserver {\r\n    listen  80;\r\n    server_name     product.test.com;\r\n    location \/ {\r\n        root   \/home\/www\/product;\r\n        index  index.html index.htm;\r\n    }\r\n}<\/pre>\n

2\uff09\u53c2\u8003\u65b9\u6848\u4e00\uff0c\u914d\u7f6e\u5b8c\u6210\u540e\u4fdd\u5b58\uff0c\u91cd\u542fnginx\u670d\u52a1\uff0c\u8bbf\u95ee\u6d4b\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u7531\u4e8e\u516c\u53f8\u4e00\u53f0\u670d\u52a1\u5668\u540c\u65f6\u6709\u591a\u4e2a\u670d\u52a1\uff0c\u8fd9\u4e9b\u670d\u52a1\u901a\u8fc7\u57df\u540d\u89e3\u6790\u90fd\u5e0c\u671b\u76d1\u542c80\/443\u7aef\u53e3\u76f4\u63a5\u901a\u8fc7\u57df\u540d\u8bbf\u95ee\uff0c\u6bd4\u5982\u6709dem […]<\/p>\n","protected":false},"author":1482,"featured_media":110704,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-253958","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/253958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1482"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=253958"}],"version-history":[{"count":3,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/253958\/revisions"}],"predecessor-version":[{"id":254007,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/253958\/revisions\/254007"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/110704"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=253958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=253958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=253958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}