{"id":13682,"date":"2024-02-26T15:10:29","date_gmt":"2024-02-26T07:10:29","guid":{"rendered":"https:\/\/92it.top\/?p=13682"},"modified":"2024-02-26T15:10:29","modified_gmt":"2024-02-26T07:10:29","slug":"%e4%bd%bf%e7%94%a8docker%e5%ae%89%e8%a3%85%e5%b9%b6%e5%90%af%e5%8a%a8nginx","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=13682","title":{"rendered":"\u4f7f\u7528Docker\u5b89\u88c5\u5e76\u542f\u52a8nginx"},"content":{"rendered":"\n<p><strong>1. \u5728 Docker \u955c\u50cf\u4ed3\u5e93\u67e5\u627e nginx \u955c\u50cf<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/hub.docker.com\/\" target=\"_blank\">dockerhub \u955c\u50cf\u4ed3\u5e93<\/a><\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-99-998x1024.png\" alt=\"\" class=\"wp-image-13683\" width=\"488\" height=\"500\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-99-998x1024.png 998w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-99-292x300.png 292w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-99-768x788.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-99-830x852.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-99-230x236.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-99-350x359.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-99-480x493.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-99.png 1444w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/figure><\/div>\n\n\n\n<p>\u6216\u8005\u901a\u8fc7\u547d\u4ee4 docker search nginx \u5728\u5bbf\u4e3b\u673a\u7ec8\u7aef\u67e5\u627e<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u62c9\u53d6 nginx \u955c\u50cf\ndocker pull nginx           # \u4e0d\u52a0\u7248\u672c\u53f7\u9ed8\u8ba4\u4e0b\u8f7d latest \u7248\u672c\uff0c\u5373 docker pull nginx:latest\n\n# \u67e5\u770b\u955c\u50cf\ndocker images<\/pre>\n\n\n\n<p><strong>2. \u62c9\u53d6 nginx \u955c\u50cf<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u62c9\u53d6 nginx \u955c\u50cf\ndocker pull nginx           # \u4e0d\u52a0\u7248\u672c\u53f7\u9ed8\u8ba4\u4e0b\u8f7d latest \u7248\u672c\uff0c\u5373 docker pull nginx:latest\n\n# \u67e5\u770b\u955c\u50cf\ndocker images<\/pre>\n\n\n\n<p><strong>3. \u8fd0\u884c\u955c\u50cf\uff08\u4f7f\u7528 nginx:latest \u955c\u50cf\u521b\u5efa\u5bb9\u5668\uff09<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5148\u5728\u5bbf\u4e3b\u673a\u7684\u6839\u76ee\u5f55\u4e2d\u521b\u5efa\u6302\u8f7d\u76ee\u5f55<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mkdir -p \/docker\/nginx\/conf         # nginx \u5b58\u653e\u914d\u7f6e\u6587\u4ef6\u7684\u76ee\u5f55\nmkdir -p \/docker\/nginx\/logs         # nginx \u5b58\u653e\u65e5\u5fd7\u7684\u76ee\u5f55\nmkdir -p \/docker\/nginx\/html         # nginx \u542f\u52a8\u7f51\u7ad9\u76ee\u5f55\uff08\u5b58\u653e\u9759\u6001\u6587\u4ef6\u7684\u76ee\u5f55\uff09<\/pre>\n\n\n\n<p>\u7136\u540e\u5c06 nginx \u955c\u50cf\u4e2d\u7684\u90e8\u5206\u6587\u4ef6\u62f7\u8d1d\u5230\u5bbf\u4e3b\u673a\u7684\u6302\u8f7d\u76ee\u5f55\u4e2d<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># 1. \u5148\u4f7f\u7528 nginx \u955c\u50cf\u521b\u5efa nginx \u5bb9\u5668\uff0c\u5c06\u6587\u4ef6\u62f7\u8d1d\u51fa\u6765\u5148\ndocker run --name nginx -d -p 80:80 nginx\n\n# 2. \u5c06\u5bb9\u5668\u4e2d\u7684 nginx.conf \u6587\u4ef6\u62f7\u8d1d\u5230\u5bbf\u4e3b\u673a\u4e2d\ndocker cp nginx:\/etc\/nginx\/nginx.conf \/docker\/nginx\/conf\/nginx.conf\n\n# 3. \u5c06\u5bb9\u5668\u4e2d conf.d \u6587\u4ef6\u5939\uff08\u5305\u62ec\u91cc\u9762\u7684\u6587\u4ef6\uff09\u62f7\u8d1d\u5230\u5bbf\u4e3b\u673a\u4e2d\ndocker cp nginx:\/etc\/nginx\/conf.d \/docker\/nginx\/conf\/conf.d\n\n# 4. \u5c06\u5bb9\u5668\u4e2d\u7684 html \u6587\u4ef6\u5939\u62f7\u8d1d\u5230\u5bbf\u4e3b\u673a\u4e2d\ndocker cp nginx:\/usr\/share\/nginx\/html \/docker\/nginx\/\n\n<\/pre>\n\n\n\n<p>\u505c\u6b62\u521a\u521a\u8fd0\u884c\u7684 nginx \u5bb9\u5668<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># \u505c\u6b62 nginx \u5bb9\u5668\ndocker stop nginx\n\n# \u5220\u9664 nginx \u5bb9\u5668\ndocker rm nginx\n\n# \u5220\u9664\u6b63\u5728\u8fd0\u884c\u7684 nginx \u5bb9\u5668\ndocker rm -f nginx\n<\/pre>\n\n\n\n<p>\u91cd\u65b0\u4f7f\u7528 nginx \u955c\u50cf\u521b\u5efa nginx \u5bb9\u5668\uff0c\u5e76\u6302\u8f7d\u5bb9\u5668\u6570\u636e\u5377\u5230\u5bbf\u4e3b\u673a\u76ee\u5f55\u4e2d<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\"># \u8981\u6267\u884c\u7684\u547d\u4ee4\ndocker run -p 80:80 --name nginx -v \/docker\/nginx\/conf\/nginx.conf:\/etc\/nginx\/nginx.conf -v \/docker\/nginx\/conf\/conf.d:\/etc\/nginx\/conf.d -v \/docker\/nginx\/logs:\/var\/log\/nginx -v \/docker\/nginx\/html:\/usr\/share\/nginx\/html -d --restart=always nginx:latest\n\n# \u65b9\u4fbf\u9605\u8bfb\ndocker run -p 80:80 --name nginx \\\n-v \/docker\/nginx\/conf\/nginx.conf:\/etc\/nginx\/nginx.conf \\\n-v \/docker\/nginx\/conf\/conf.d:\/etc\/nginx\/conf.d \\\n-v \/docker\/nginx\/logs:\/var\/log\/nginx \\\n-v \/docker\/nginx\/html:\/usr\/share\/nginx\/html \\\n-d \\\n--restart=always \\\nnginx:latest<\/pre>\n\n\n\n<p>\u547d\u4ee4\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul><li><code>-p 80:80<\/code> \u6307\u5b9a\u7aef\u53e3\u6620\u5c04\uff0c\u683c\u5f0f\u4e3a\uff1a\u4e3b\u673a(\u5bbf\u4e3b)\u7aef\u53e3:\u5bb9\u5668\u7aef\u53e3<\/li><li><code>--name nginx<\/code> \u547d\u540d\u542f\u52a8\u7684\u5bb9\u5668\u540d\u5b57\u4e3a nginx<\/li><li><code>-v<\/code> \u8f7d\u6587\u4ef6\u6216\u76ee\u5f55\uff1a\u524d\u9762\u662f\u5bbf\u4e3b\u673a\u90e8\u5206\uff0c\u540e\u9762\u662f\u5bb9\u5668\u90e8\u5206<\/li><li><code>-d<\/code> \u8868\u793a\u540e\u53f0\u542f\u52a8\u5bb9\u5668<\/li><li><code>--restart=always<\/code> \u91cd\u542f\u6a21\u5f0f\uff0c\u6bcf\u6b21\u542f\u52a8 docker \u90fd\u4f1a\u81ea\u52a8\u91cd\u542f nginx \u5bb9\u5668\u3002<\/li><li><code>nginx:latest<\/code> \u8868\u793a\u4f7f\u7528\u8be5\u955c\u50cf\u521b\u5efa\u5bb9\u5668<\/li><\/ul>\n\n\n\n<p><strong>4. \u8fd0\u884c\u6548\u679c<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-100-1024x530.png\" alt=\"\" class=\"wp-image-13684\" width=\"548\" height=\"283\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-100-1024x530.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-100-300x155.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-100-768x398.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-100-830x430.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-100-230x119.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-100-350x181.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-100-480x248.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-100.png 1530w\" sizes=\"(max-width: 548px) 100vw, 548px\" \/><\/figure><\/div>\n\n\n\n<p>\u4ee5\u5bb9\u5668\u5185\u7684\u76ee\u5f55\u6765\u8bf4\u660e\uff0cnginx \u542f\u52a8\u540e\uff0c\u52a0\u8f7d\u4e86\u4e3b\u914d\u7f6e\u6587\u4ef6 <code>\/etc\/nginx\/nginx.conf <\/code>\uff0c\u7136\u540e\u4e3b\u914d\u7f6e\u6587\u4ef6\u4e2d\u6709\u8fd9\u4e48\u4e00\u53e5\u914d\u7f6e\uff1a<code>include \/etc\/nginx\/conf.d\/*.conf;<\/code>\uff0c\u76f8\u5f53\u4e8e\u5f15\u7528\u4e86 <code>\/etc\/nginx\/conf.d\/*.conf<\/code> \u4e2d\u6240\u6709\u7684 <code>conf<\/code> \u6587\u4ef6\uff0c\u76ee\u524d <code>\/etc\/nginx\/conf.d<\/code> \u4e2d\u53ea\u6709\u4e00\u4e2a <code>default.conf<\/code> \u6587\u4ef6\uff0c\u91cc\u9762\u8bbe\u5b9a\u4e86\u6b22\u8fce\u9875\u9762\u4e3a <code>\/usr\/share\/nginx\/html\/index.html<\/code> \u6587\u4ef6\u3002\u5982\u679c\u9700\u8981\u66f4\u8be6\u7ec6\u7684\u8bf4\u660e\uff0c\u8bf7\u76f4\u63a5\u67e5\u770b\u4e3b\u914d\u7f6e\u6587\u4ef6 <code>\/etc\/nginx\/nginx.conf <\/code>\u3002<\/p>\n\n\n\n<p><strong>5. \u8fd0\u884c\u6548\u679c<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>\u5c1d\u8bd5\u66f4\u6539\u6b22\u8fce\u9875\u9762\u7684 html<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-101-892x1024.png\" alt=\"\" class=\"wp-image-13685\" width=\"446\" height=\"512\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-101-892x1024.png 892w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-101-261x300.png 261w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-101-768x882.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-101-830x953.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-101-230x264.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-101-350x402.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-101-480x551.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-101.png 1310w\" sizes=\"(max-width: 446px) 100vw, 446px\" \/><\/figure><\/div>\n\n\n\n<p>\u5728\u6d4f\u89c8\u5668\u4e0a\u5237\u65b0\uff0c\u5c31\u53ef\u4ee5\u770b\u5230\u4fee\u6539\u540e\u7684\u5185\u5bb9\u4e86<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-102-1024x498.png\" alt=\"\" class=\"wp-image-13686\" width=\"508\" height=\"246\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-102-1024x498.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-102-300x146.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-102-768x373.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-102-830x404.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-102-230x112.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-102-350x170.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-102-480x233.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2024\/02\/image-102.png 1308w\" sizes=\"(max-width: 508px) 100vw, 508px\" \/><\/figure><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. \u5728 Docker \u955c\u50cf\u4ed3\u5e93\u67e5\u627e nginx \u955c\u50cf dockerhub \u955c\u50cf\u4ed3\u5e93 \u6216\u8005\u901a\u8fc7\u547d\u4ee4 docke [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,20],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/13682"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13682"}],"version-history":[{"count":1,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/13682\/revisions"}],"predecessor-version":[{"id":13687,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/13682\/revisions\/13687"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}