{"id":509,"date":"2024-10-29T22:56:48","date_gmt":"2024-10-29T14:56:48","guid":{"rendered":"https:\/\/www.hyy.net\/?p=509"},"modified":"2024-10-29T22:56:48","modified_gmt":"2024-10-29T14:56:48","slug":"docker-install-nginx","status":"publish","type":"post","link":"https:\/\/diji.net\/?p=509","title":{"rendered":"Docker\u914d\u7f6enginx"},"content":{"rendered":"<h1>Docker\u914d\u7f6enginx<\/h1>\n<p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728Docker\u4e2d\u5b89\u88c5\u548c\u914d\u7f6eNginx\uff0c\u5305\u62ec\u5b89\u88c5\u547d\u4ee4\u3001\u67e5\u770b\u5bb9\u5668\u3001\u8fd0\u884c\u6d4b\u8bd5\u3001\u6587\u4ef6\u6620\u5c04\u4ee5\u53caNginx\u670d\u52a1\u7684\u914d\u7f6e\u548c\u90e8\u7f72\u3002\u91cd\u70b9\u8ba8\u8bba\u4e86\u6587\u4ef6\u6620\u5c04\u7684\u91cd\u8981\u6027\uff0c\u4ee5\u4fbf\u4e8e\u5728\u4e3b\u673a\u4e0a\u76f4\u63a5\u7f16\u8f91Nginx\u914d\u7f6e\u548c\u7ba1\u7406\u6587\u4ef6\u3002\u6b64\u5916\uff0c\u8fd8\u8bb2\u89e3\u4e86\u6b63\u5411\u4ee3\u7406\u548c\u53cd\u5411\u4ee3\u7406\u7684\u6982\u5ff5\uff0c\u5e76\u7ed9\u51fa\u4e86\u53cd\u5411\u4ee3\u7406\u7684\u914d\u7f6e\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u901a\u8fc7Nginx\u4ee3\u7406\u8bbf\u95ee\u4e0d\u540c\u57df\u540d\u7684\u670d\u52a1\u3002<\/p>\n<h3>Docker\u5b89\u88c5nginx<\/h3>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndocker search nginx\ndocker pull nginx\n<\/pre>\n<p>\u67e5\u770b\u662f\u5426\u5b89\u88c5<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndocker images\n<\/pre>\n<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~# docker pull nginx\nUsing default tag: latest\nlatest: Pulling from library\/nginx\na480a496ba95: Pull complete\nf3ace1b8ce45: Pull complete\n11d6fdd0e8a7: Pull complete\nf1091da6fd5c: Pull complete\n40eea07b53d8: Pull complete\n6476794e50f4: Pull complete\n70850b3ec6b2: Pull complete\nDigest: sha256:28402db69fec7c17e179ea87882667f1e054391138f77ffaf0c3eb388efc3ffb\nStatus: Downloaded newer image for nginx:latest\ndocker.io\/library\/nginx:latest\nroot@debian:~# docker images\nREPOSITORY   TAG       IMAGE ID       CREATED       SIZE\nnginx        latest    3b25b682ea82   3 weeks ago   192MB\n<\/pre>\n<\/p>\n<p>\u8fd0\u884c\u6d4b\u8bd5nginx<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndocker run --name nginx-test -p 9091:80 -d nginx\n<\/pre>\n<\/p>\n<p>--name  #\u7ed9\u4f60\u542f\u52a8\u7684\u5bb9\u5668\u8d77\u4e2a\u540d\u5b57\uff0c\u4ee5\u540e\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u540d\u5b57\u542f\u52a8\u6216\u8005\u505c\u6b62\u5bb9\u5668<br \/>\n-p #\u6620\u5c04\u7aef\u53e3\uff0c\u5c06docker\u5bbf\u4e3b\u673a\u76849091\u7aef\u53e3\u548c\u5bb9\u5668\u768480\u7aef\u53e3\u8fdb\u884c\u7ed1\u5b9a<br \/>\n-v #\u6302\u8f7d\u6587\u4ef6\u7528\u7684<br \/>\n-d #\u8868\u793a\u542f\u52a8\u7684\u662f\u54ea\u4e2a\u955c\u50cf\u3002<\/p>\n<p>\u6d4b\u8bd5\u662f\u5426\u542f\u52a8\u6210\u529f<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~# wget &lt;a href=&quot;http:\/\/localhost:9091&quot;&gt;http:\/\/localhost:9091&lt;\/a&gt;\n--2024-10-29 20:43:28--  &lt;a href=&quot;http:\/\/localhost:9091\/&quot;&gt;http:\/\/localhost:9091\/&lt;\/a&gt;\nResolving localhost (localhost)... ::1, 127.0.0.1\nConnecting to localhost (localhost)|::1|:9091... connected.\nHTTP request sent, awaiting response... 200 OK\nLength: 615 &#x5B;text language=&amp;quot;\/html&amp;quot;]&#x5B;\/text]\nSaving to: \u2018index.html\u2019\nindex.html                                 100%&#x5B;======================================================================================&amp;gt;]     615  --.-KB\/s    in 0s\n2024-10-29 20:43:28 (135 MB\/s) - \u2018index.html\u2019 saved &#x5B;615\/615]\n<\/pre>\n<\/p>\n<h3>Nginx\u670d\u52a1\u7684\u914d\u7f6e\u548c\u90e8\u7f72<\/h3>\n<p>\u4e3a\u4ec0\u4e48\u9700\u8981\u505a\u6587\u4ef6\u7684\u6620\u5c04\uff1f<br \/>\n\u6211\u4eec\u5728\u4f7f\u7528\u5bb9\u5668\u7684\u8fc7\u7a0b\u4e2d\u9700\uff0c\u6709\u65f6\u5019\u9700\u8981\u5bf9\u5bb9\u5668\u4e2d\u7684\u6587\u4ef6\u8fdb\u884c\u4fee\u6539\u7ba1\u7406\uff0c\u5982\u679c\u4e0d\u505a\u6587\u4ef6\u6620\u5c04\u7684\u5316\uff0c\u6211\u4eec\u4f7f\u7528docker exec -it \u5bb9\u5668ID\/\u5bb9\u5668\u540d \/bin\/bash \u624d\u80fd\u8fdb\u5165nginx\u4e2d\u7684\u6587\u4ef6\u91cc\u9762\u3002<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndocker exec -it nginx-test \/bin\/bash\n<\/pre>\n<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~# docker exec -it nginxtest \/bin\/bash\nError: No such container: nginxtest\nroot@debian:~# docker ps\nCONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES\nee033e7b4b95   nginx     &quot;\/docker-entrypoint.\u2026&quot;   3 minutes ago   Up 3 minutes   0.0.0.0:9091-&gt;80\/tcp, :::9091-&gt;80\/tcp   nginx-test\nroot@debian:~# docker exec -it nginx-test \/bin\/bash\nroot@ee033e7b4b95:\/# ls\nbin  boot  dev  docker-entrypoint.d  docker-entrypoint.sh  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var\nroot@ee033e7b4b95:\/# cd \/etc\/nginx\nroot@ee033e7b4b95:\/etc\/nginx# ls\nconf.d  fastcgi_params  mime.types  modules  nginx.conf  scgi_params  uwsgi_params\nroot@ee033e7b4b95:\/etc\/nginx# cd conf.d\nroot@ee033e7b4b95:\/etc\/nginx\/conf.d# ls\ndefault.conf\n<\/pre>\n<\/p>\n<p>\u5982\u679c\u628a\u5173\u952e\u6587\u4ef6\u6620\u5c04\u5230\u4e3b\u673a\u4e0a\uff0c\u90a3\u4e48\u5c31\u53ef\u4ee5\u5728\u4e3b\u673a\u4e2d\u8fdb\u884c\u4fee\u6539\u800c\u4e0d\u5fc5\u8fdb\u5165\u6587\u4ef6\u5f53\u4e2d\u624d\u8fdb\u884c\u4fee\u6539\u4e86\u3002<\/p>\n<p>\u9700\u8981\u5728\u4e3b\u673a\u4e0a\u5efa\u7acb\u76f8\u5e94\u7684\u5173\u952e\u6587\u4ef6\u76ee\u5f55<\/p>\n<ul>\n<li>\u5728home\u4e0b\u521b\u5efa\u4e00\u4e2adocker\u6587\u4ef6\u5939\uff0c\u7528\u6765\u4e13\u95e8\u5b58docker\u5bb9\u5668\u7684\u6620\u5c04\u6587\u4ef6\u3002<\/li>\n<li>\u5728docker\u4e0b\u521b\u5efa\u4e00\u4e2anginx\u7684\u6587\u4ef6\u5939\uff0c\u7528\u4e8e\u5b58nginx\u7684\u6620\u5c04\u6587\u4ef6\u3002<\/li>\n<li>\u5728nginx\u4e0b\u521b\u5efa\u4e09\u4e2a\u5173\u952e\u7684\u6620\u5c04\u6587\u4ef6\u3002<\/li>\n<li>www\u6587\u4ef6\u6620\u5c04www\u76ee\u5f55\uff0c\u4e5f\u5c31\u662f\u7f51\u9875\u76ee\u5f55\u3002<\/li>\n<li>logs\u6587\u4ef6\u6620\u5c04\u65e5\u5fd7\u76ee\u5f55\u3002<\/li>\n<li>conf\u6587\u4ef6\u6620\u5c04\u914d\u7f6e\u76ee\u5f55<\/li>\n<\/ul>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~# mkdir docker &amp;&amp; cd docker &amp;&amp; mkdir nginx &amp;&amp; cd nginx\nroot@debian:~\/docker\/nginx# mkdir www logs conf\nroot@debian:~\/docker\/nginx# ls\nconf  logs  www\nroot@debian:~\/docker\/nginx#\n<\/pre>\n<\/p>\n<p>\u5148\u5728\u5bb9\u5668\u4e2d\u62f7\u8d1d\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndocker cp \u5bb9\u5668ID\uff1a\/etc\/nginx\/nginx.conf \/home\/docker\/nginx\/conf\n<\/pre>\n<p>\u6ce8\u610f\u6b64\u65f6\u7684\u5bb9\u5668\u5fc5\u987b\u662f\u8fd0\u884c\u7684<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~\/docker\/nginx# docker ps\nCONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES\nee033e7b4b95   nginx     &quot;\/docker-entrypoint.\u2026&quot;   3 minutes ago   Up 3 minutes   0.0.0.0:9091-&gt;80\/tcp, :::9091-&gt;80\/tcp   nginx-test\nroot@debian:~\/docker\/nginx# docker cp ee033e7b4b95:\/etc\/nginx\/nginx.conf \/root\/docker\/nginx\/conf\n<\/pre>\n<\/p>\n<p>docker\u4e2dnginx\u4e0e\u4e3b\u673a\u6587\u4ef6\u6620\u5c04\u89c4\u5219\u5982\u4e0b<\/p>\n<p>\u4e3b\u673a<br \/>\ndocker<\/p>\n<p>\/root\/docker\/nginx\/www<br \/>\n\/usr\/share\/nginx\/html #\u7f51\u9875\u6587\u4ef6<\/p>\n<p>\/root\/docker\/nginx\/conf\/nginx.conf<br \/>\n\/etc\/nginx\/nginx.conf#\u914d\u7f6e\u6587\u4ef6<\/p>\n<p>\/root\/docker\/nginx\/logs<br \/>\n\/var\/log\/nginx#\u65e5\u5fd7\u6587\u4ef6<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~\/docker\/nginx# docker cp ee033e7b4b95:\/usr\/share\/nginx\/html \/root\/docker\/nginx\/www\nroot@debian:~\/docker\/nginx# docker cp ee033e7b4b95:\/var\/log\/nginx \/root\/docker\/nginx\/logs\n<\/pre>\n<\/p>\n<p>\u5173\u95ed\u4e4b\u524d\u8fd0\u884c\u7684\u5bb9\u5668\u5e76\u5220\u9664\u5bb9\u5668<br \/>\ndocker stop \u5bb9\u5668ID<br \/>\ndocker rm \u5bb9\u5668ID<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~\/docker\/nginx# docker ps\nCONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                                   NAMES\nee033e7b4b95   nginx     &quot;\/docker-entrypoint.\u2026&quot;   16 minutes ago   Up 16 minutes   0.0.0.0:9091-&gt;80\/tcp, :::9091-&gt;80\/tcp   nginx-test\nroot@debian:~\/docker\/nginx# docker stop ee033e7b4b95 &amp;&amp; docker rm ee033e7b4b95\nee033e7b4b95\nee033e7b4b95\n<\/pre>\n<\/p>\n<p>\u8fd0\u884cnginx\uff0c\u540c\u65f6\u8fdb\u884c\u6587\u4ef6\u6302\u8f7d<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ndocker run -d -p 9091:80  --name nginx-test -v \/root\/docker\/nginx\/www:\/usr\/share\/nginx\/html -v \/root\/docker\/nginx\/conf\/nginx.conf:\/etc\/nginx\/nginx.conf -v \/root\/docker\/nginx\/logs:\/var\/log\/nginx nginx\n<\/pre>\n<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~\/docker\/nginx# docker run -d -p 9091:80  --name nginx-test -v \/root\/docker\/nginx\/www:\/usr\/share\/nginx\/html -v \/root\/docker\/nginx\/conf\/nginx.conf:\/etc\/nginx\/nginx.conf -v \/root\/docker\/nginx\/logs:\/var\/log\/nginx nginx\n6d381d523815ff37c4a59fed1696fbc74af35cdf767ba532f3c3d42881403188\n<\/pre>\n<\/p>\n<p>\u6d4b\u8bd5\u4ee5\u4e0b<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~\/docker\/nginx# wget &lt;a href=&quot;http:\/\/localhost:9091&quot;&gt;http:\/\/localhost:9091&lt;\/a&gt;\n--2024-10-29 21:00:15--  &lt;a href=&quot;http:\/\/localhost:9091\/&quot;&gt;http:\/\/localhost:9091\/&lt;\/a&gt;\nResolving localhost (localhost)... ::1, 127.0.0.1\nConnecting to localhost (localhost)|::1|:9091... connected.\nHTTP request sent, awaiting response... 403 Forbidden\n2024-10-29 21:00:15 ERROR 403: Forbidden.\n<\/pre>\n<p>\u8fd4\u56de403\u9519\u8bef\uff0cnginx\u7684http\u670d\u52a1\u5df2\u5f00\u901a\uff0c\u4f46\u662f\u670d\u52a1\u5668\u4e0a\u6ca1\u6709\u5f00\u76ee\u5f55\u6d4f\u89c8\u6216\u8005\u6ca1\u6709index.html\u6587\u4ef6\u3002<\/p>\n<p>\u5728www\u76ee\u5f55\u4e0b\u5efa\u7acb\u4e00\u4e2ahtml\u6587\u4ef6<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\necho &quot;it works,nginx is runing&quot; &gt; \/root\/docker\/nginx\/www\/index.html\n<\/pre>\n<p>\u6d4b\u8bd5\u4e00\u4e0b<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~# wget &lt;a href=&quot;http:\/\/localhost:9091&quot;&gt;http:\/\/localhost:9091&lt;\/a&gt;\n--2024-10-29 21:09:48--  &lt;a href=&quot;http:\/\/localhost:9091\/&quot;&gt;http:\/\/localhost:9091\/&lt;\/a&gt;\nResolving localhost (localhost)... ::1, 127.0.0.1\nConnecting to localhost (localhost)|::1|:9091... connected.\nHTTP request sent, awaiting response... 200 OK\nLength: 25 &#x5B;text language=&amp;quot;\/html&amp;quot;]&#x5B;\/text]\nSaving to: \u2018index.html\u2019\nindex.html                                 100%&#x5B;======================================================================================&amp;gt;]      25  --.-KB\/s    in 0s\n2024-10-29 21:09:48 (6.35 MB\/s) - \u2018index.html\u2019 saved &#x5B;25\/25]\nroot@debian:~# cat index.html\nit works,nginx is runing\n<\/pre>\n<\/p>\n<p>nginx\u8fd4\u56de\u4e86\u4e00\u4e2aindex.html\u6587\u4ef6\u4fdd\u5b58\u5728\u5f53\u524d\u6587\u4ef6\u5939,\u4f7f\u7528cat\u67e5\u770b\u6587\u4ef6\u5185\u5bb9\uff0c\u5373\u663e\u793ait works,nginx is runing<br \/>\n\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165\u7f51\u5740http:\/\/ip:9091,  ip\u6362\u6210DOCKER\u4e3b\u673a\u7684IP\u5730\u5740\uff0c \u663e\u793a\u4e00\u6837\u7684\u5185\u5bb9\u3002<\/p>\n<h3>Nginx\u7684\u666e\u901a\u914d\u7f6e<\/h3>\n<p>\u901a\u8fc7nginx\u4e3a\u591a\u4e3a\u4e2a\u57df\u540d\u914d\u7f6e\u670d\u52a1\uff0c\u4f7f\u5f97\u901a\u8fc7\u6d4f\u89c8\u5668\u53ef\u4ee5\u8bbf\u95ee\u5230\u76f8\u5e94\u7684\u57df\u540d\u3002<\/p>\n<p>\u521b\u5efahtml\u6587\u4ef6<br \/>\n\u5728\u6620\u5c04\u5230\u4e3b\u673a\u4e0b\u7684\/root\/docker\/nginx\/www\u4e0b\u521b\u5efahtml\u6587\u4ef6\u6216\u8005\u57df\u540d\u7684\u6587\u4ef6\u5939<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~\/docker\/nginx\/www# mkdir www.abc.com www.dba.com\nroot@debian:~\/docker\/nginx\/www# ls\nwww.abc.com\nroot@debian:~\/docker\/nginx\/www#\n<\/pre>\n<\/p>\n<p>\u5176\u4e2dwww.abc.com\u548cwww.dba.com\u662f\u5b58\u653e\u4e0d\u540c\u57df\u540d\u8bbf\u95ee\u7684\u6587\u4ef6\u8def\u5f84\u3002\u91cc\u9762\u90fd\u6709\u5bf9\u5e94\u7684index.html<\/p>\n<p>\u4fee\u6539host\u6587\u4ef6<br \/>\n\u5728DNS\u4e2d\u505a\u4e86\u57df\u540d\u89e3\u6790\u7684\u8bdd\u4e0d\u9700\u8981\u4fee\u6539host\u6587\u4ef6\uff0c\u8fd9\u91cc\u7eaf\u7cb9\u662f\u6d4b\u8bd5\u3002<\/p>\n<p><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\n127.0.0.1       localhost\n127.0.1.1       debian\n127.0.0.1 www.abc.com\n127.0.0.1 www.dba.com\n<\/pre>\n<\/p>\n<p>NANO\u53ef\u4ee5\u4f7f\u7528\u952e\u76d8\u7684\u5220\u9664\u3001\u9000\u683c\u3001\u4e0b\u4e00\u884c\u7b49\u529f\u80fd\u952e\u3002\u4fee\u6539\u5b8c\u6309CTRL_O\u518d\u6309\u56de\u8f66\u952e\u4fdd\u5b58\uff0c\u6309CTRL+X\u63a8\u51faNANO\u3002<br \/>\n\u6d4b\u8bd5\u4e00\u4e0b<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~\/docker\/nginx\/www# ping www.abc.com\nPING www.abc.com (127.0.0.1) 56(84) bytes of data.\n64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.042 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.039 ms\n...\n<\/pre>\n<\/p>\n<p>\u4fee\u6539nginx.conf\u6587\u4ef6<\/p>\n<p>\u63d0\u9192\u300c\u8def\u5f84\u95ee\u9898\u300d<br \/>\n\u8fd9\u91cc\u9700\u8981\u63d0\u9192\u4e00\u4e0b\uff0c\u5728\u524d\u9762\u6211\u4eec\u5df2\u7ecf\u628anginx\u4e2d\u7684\u914d\u7f6e\u6587\u4ef6\u6620\u5c04\u5230\u4e3b\u673a\u76ee\u5f55\u4e0b\uff0c\u6211\u4eec\u5728\u4e3b\u673a\u76ee\u5f55\u4e0b\u4fee\u6539\u4e86\/root\/docker\/nginx\/www\u7684\u6587\u4ef6\uff0c\u540c\u65f6nginx\u5bb9\u5668\u4e2d\u7684\/usr\/share\/nginx\/html\u4e0b\u7684\u6587\u4ef6\u6709\u4f1a\u6709\u76f8\u540c\u7684\u53d8\u5316\u3002\u4f46\u662f\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u4f7f\u7528\u7684\u8def\u5f84\u5f97\u662fnginx\u7684\uff0c\u800c\u4e0d\u5e94\u8be5\u662f\u4e3b\u673a\u7684\u8def\u5f84\u3002<\/p>\n<p>\u6253\u5f00\u4e3b\u673a\u6620\u5c04\u7684nginx\u914d\u7f6e\u6587\u4ef6<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nroot@debian:~# nano \/root\/docker\/nginx\/conf\/nginx.conf\n<\/pre>\n<\/p>\n<pre><code>user  nginx;\nworker_processes  auto;\n\nerror_log  \/var\/log\/nginx\/error.log notice;\npid        \/var\/run\/nginx.pid;\n\nevents {\n    worker_connections  1024;\n}\n\nhttp {\n    include       \/etc\/nginx\/mime.types;\n    default_type  application\/octet-stream;\n    log_format  main  &#039;$remote_addr - $remote_user [$time_local] &quot;$request&quot; &#039;\n                      &#039;$status $body_bytes_sent &quot;$http_referer&quot; &#039;\n                      &#039;&quot;$http_user_agent&quot; &quot;$http_x_forwarded_for&quot;&#039;;\n\n    access_log  \/var\/log\/nginx\/access.log  main;\n    sendfile        on;\n    #tcp_nopush     on;\n    keepalive_timeout  65;\n    #gzip  on;\n    include \/etc\/nginx\/conf.d\/*.conf;\n\n    # \u914d\u7f6e\u670d\u52a1www.abc.com\n    server{\n        #\u76d1\u542c\u7aef\u53e3\n        listen 80;\n        #\u914d\u7f6e\u57df\u540d\n        server_name www.abc.com;\n        #\u914d\u7f6e\u7f51\u7ad9\u8ddf\u76ee\u5f55\n        root \/usr\/share\/nginx\/html\/www.abc.com;\n        location \/ {\n                #\u8ddf\u76ee\u5f55\n                root \/usr\/share\/nginx\/html\/www.abc.com;\n                #\u9ed8\u8ba4\u9996\u9875\n                index index.html index.htm;\n            }  \n        }\n}<\/code><\/pre>\n<p>\u91cd\u542fdocker\u5bb9\u5668<br \/>\ndocker ps#\u83b7\u53d6\u5bb9\u5668\u7684ID<br \/>\ndocker restart \u5bb9\u5668ID<\/p>\n<pre><code>root@debian:~# docker ps\nCONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                   NAMES\n201da9573fce   nginx     &quot;\/docker-entrypoint.\u2026&quot;   3 minutes ago   Up 3 minutes   0.0.0.0:9091-&gt;80\/tcp, :::9091-&gt;80\/tcp   nginx-test\nroot@debian:~# docker restart 201da9573fce\n201da9573fce<\/code><\/pre>\n<p>\u6d4b\u8bd5\u4e00\u4e0b<\/p>\n<pre><code>root@debian:~# wget http:\/\/www.abc.com:9091\n--2024-10-29 22:23:44--  http:\/\/www.abc.com:9091\/\nResolving www.abc.com (www.abc.com)... 127.0.0.1\nConnecting to www.abc.com (www.abc.com)|127.0.0.1|:9091... connected.\nHTTP request sent, awaiting response... 200 OK\nLength: 12 \nSaving to: \u2018index.html\u2019\n\nindex.html                                 100%[======================================================================================&gt;]      12  --.-KB\/s    in 0s\n\n2024-10-29 22:23:44 (3.05 MB\/s) - \u2018index.html\u2019 saved [12\/12]<\/code><\/pre>\n<p>\u6ce8\u610f\uff1a<br \/>\n\u6211\u4eec\u542f\u52a8nginx\u5bb9\u5668\u65f6\uff0c\u7528\u7684\u4e00\u76f4\u662f\u628a\u5bb9\u5668\u768480\u7aef\u53e3\u6620\u5c04\u5230\u4e3b\u673a\u76849091\u7aef\u53e3\uff0c\u5728\u914d\u7f6eWWW.ABC.COM\u65f6\u7528\u768480\u7aef\u53e3\uff0c\u5728docker\u5bbf\u4e3b\u673a\u4e0a\u8bbf\u95ee\u65f6\u4e5f\u8981\u52a0\u4e0a9091\u7aef\u53e3\u3002<\/p>\n<p>\u4ee5\u540c\u6837\u7684\u65b9\u5f0f\u914d\u7f6e\u5176\u4ed6\u57df\u540d<br \/>\n\u300c\u4fee\u6539nginx.conf\u300d\u2013\u300c\u6dfb\u52a0\u4e00\u4e2aserver\u300d\u2013\u300c\u91cd\u542fdocker\u300d\u2013\u300c\u6d4f\u89c8\u5668\u57df\u540d\u8bbf\u95ee\u6d4b\u8bd5\u300d<\/p>\n<p>\u9519\u8bef\u5fc3\u5f97<br \/>\n\u5f53\u6709\u65f6\u542f\u52a8\u5bb9\u5668\uff0c\u901a\u8fc7docker ps \u53d1\u73b0\u5bb9\u5668\u5e76\u6ca1\u6709\u542f\u52a8\uff0c\u90a3\u4e48\u901a\u8fc7docker ps -a\u53ef\u67e5\u770b\u5bb9\u5668\u7684\u72b6\u6001\uff1a<br \/>\ncreated\uff08\u5df2\u521b\u5efa\uff09<br \/>\nrestarting\uff08\u91cd\u542f\u4e2d\uff09<br \/>\nrunning\uff08\u8fd0\u884c\u4e2d\uff09<br \/>\nremoving\uff08\u8fc1\u79fb\u4e2d\uff09<br \/>\npaused\uff08\u6682\u505c\uff09<br \/>\nexited\uff08\u505c\u6b62\uff09<br \/>\ndead\uff08\u6b7b\u4ea1\uff09<br \/>\n\u7136\u540e\u901a\u8fc7\u67e5\u770b\u65e5\u5fd7\uff1adocker logs \u5bb9\u5668ID<br \/>\n\u53ef\u4ee5\u4ece\u4e2d\u53d1\u73b0\u672a\u80fd\u542f\u52a8\u7684\u539f\u56e0\u3002<\/p>\n<h3>\u4ee3\u7406\u6a21\u5f0f<\/h3>\n<p>\u6b63\u5411\u4ee3\u7406<br \/>\n\u5ba2\u6237\u7aef&lt;----&gt;\u4ee3\u7406\u670d\u52a1\u5668&lt;----&gt;\u670d\u52a1\u5668<br \/>\n\u67b6\u8bbe\u5728\u5ba2\u6237\u673a\u4e0e\u76ee\u6807\u4e3b\u673a\u4e4b\u95f4\uff0c\u53ea\u7528\u4e8e\u4ee3\u7406\u5185\u90e8\u7f51\u7edc\u5bf9Internet\u7684\u8fde\u63a5\u8bf7\u6c42\uff0c\u5ba2\u6237\u673a\u5fc5\u987b\u6307\u5b9a\u4ee3\u7406\u670d\u52a1\u5668\uff0c\u5e76\u5c06\u539f\u672c\u8981\u76f4\u63a5\u53d1\u9001\u5230web\u670d\u52a1\u5668\u4e0a\u7684http\u8bf7\u6c42\u53d1\u9001\u5230\u4ee3\u7406\u670d\u52a1\u5668\u4e2d\u3002<\/p>\n<p>\u53cd\u5411\u4ee3\u7406<br \/>\n\u5ba2\u6237\u7aef\u2014&gt;\u4ee3\u7406\u670d\u52a1\u5668&lt;\u2014&gt;\u670d\u52a1\u5668<br \/>\n\u53cd\u5411\u4ee3\u7406\u670d\u52a1\u5668\u67b6\u8bbe\u5728\u670d\u52a1\u7aef\uff0c\u901a\u8fc7\u7f13\u51b2\u7ecf\u5e38\u88ab\u8bf7\u6c42\u7684\u9875\u9762\u6765\u7f13\u89e3\u670d\u52a1\u5668\u7684\u5de5\u4f5c\u91cf\uff0c\u5c06\u5ba2\u6237\u673a\u8bf7\u6c42\u8f6c\u53d1\u7ed9\u5185\u90e8\u7f51\u7edc\u4e0a\u7684\u76ee\u6807\u670d\u52a1\u5668\uff1b\u5e76\u5c06\u4ece\u670d\u52a1\u5668\u4e0a\u5f97\u5230\u7684\u7ed3\u679c\u8fd4\u56de\u7ed9Internet\u4e0a\u8bf7\u6c42\u8fde\u63a5\u7684\u5ba2\u6237\u7aef\uff0c\u6b64\u65f6\u4ee3\u7406\u670d\u52a1\u5668\u4e0e\u76ee\u6807\u4e3b\u673a\u4e00\u8d77\u5bf9\u5916\u8868\u73b0\u4e3a\u4e00\u4e2a\u670d\u52a1\u5668\u3002\u6b63\u5f0f\u53cd\u5411\u4ee3\u7406\u5bf9\u771f\u6b63\u7684\u670d\u52a1\u5668\u8d77\u5230\u4e86\u4fdd\u62a4\u4f5c\u7528\uff0c\u6240\u4ee5\u53cd\u5411\u4ee3\u7406\u6bd4\u8f83\u6d41\u884c\u3002<\/p>\n<p>\u914d\u7f6e\u53cd\u5411\u4ee3\u7406<\/p>\n<p>\u901a\u8fc7\u8bbf\u95eewww.dba.com,\u6765\u8bbf\u95eewww.yini.org<\/p>\n<p>\u5728nginx\u7684\u914d\u7f6e\u5f53\u4e2d\uff0c\u65b0\u589e\u4e00\u6bb5server,<br \/>\n\u5728location\u4e2d\u6dfb\u52a0proxy_pass <a href=\"http:\/\/www.yini.org\/\">http:\/\/www.yini.org\/<\/a><\/p>\n<pre><code>\n    server{\n        #\u76d1\u542c\u7aef\u53e3\n        listen 80;\n        #\u914d\u7f6e\u57df\u540d\n        server_name www.abc.com;\n        #\u914d\u7f6e\u7f51\u7ad9\u8ddf\u76ee\u5f55\n        root \/usr\/share\/nginx\/html\/www.abc.com;\n        location \/ {\n                #\u8ddf\u76ee\u5f55\n                root \/usr\/share\/nginx\/html\/www.abc.com;\n                #\u9ed8\u8ba4\u9996\u9875\n                index index.html index.htm;\n\n            }\n        }\n\n   server {\n        listen 80;\n        server_name www.dba.com;\n\n        location \/ {\n        proxy_pass http:\/\/www.yini.org;\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        }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Docker\u914d\u7f6enginx \u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5982\u4f55\u5728Docker\u4e2d\u5b89\u88c5\u548c\u914d\u7f6eNginx\uff0c\u5305\u62ec\u5b89\u88c5\u547d\u4ee4\u3001\u67e5\u770b\u5bb9\u5668\u3001\u8fd0\u884c\u6d4b\u8bd5\u3001\u6587\u4ef6\u6620\u5c04\u4ee5\u53caNginx\u670d\u52a1\u7684\u914d\u7f6e\u548c\u90e8\u7f72\u3002\u91cd\u70b9\u8ba8\u8bba\u4e86\u6587\u4ef6\u6620\u5c04\u7684\u91cd\u8981\u6027\uff0c\u4ee5\u4fbf\u4e8e\u5728\u4e3b\u673a\u4e0a\u76f4\u63a5\u7f16\u8f91Nginx\u914d\u7f6e\u548c\u7ba1\u7406\u6587\u4ef6\u3002\u6b64\u5916\uff0c\u8fd8\u8bb2\u89e3\u4e86\u6b63\u5411\u4ee3\u7406\u548c\u53cd\u5411\u4ee3\u7406\u7684\u6982\u5ff5\uff0c\u5e76\u7ed9\u51fa\u4e86\u53cd\u5411\u4ee3\u7406\u7684\u914d\u7f6e\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u901a\u8fc7Nginx\u4ee3\u7406\u8bbf\u95ee\u4e0d\u540c\u57df\u540d\u7684\u670d\u52a1\u3002 Docker\u5b89\u88c5nginx docker search nginx docker pull nginx \u67e5\u770b\u662f\u5426\u5b89\u88c5 docker images root@debian:~# docker pull nginx Using default tag: latest latest: Pulling from library\/nginx a480a496ba95: Pull complete f3ace1b8ce45: Pull complete 11d6fdd0e8a7: Pull complete f1091da6fd5c: Pull complete 40eea07b53d8: Pull complete 6476794e50f4: Pull complete 70850b3ec6b2: Pull complete Digest: sha256:28402db69fec7c17e179ea87882667f1e054391138f77ffaf0c3eb388efc3ffb Status: Downloaded newer image for nginx:latest docker.io\/library\/nginx:latest root@debian:~# [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-509","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=509"}],"version-history":[{"count":0,"href":"https:\/\/diji.net\/index.php?rest_route=\/wp\/v2\/posts\/509\/revisions"}],"wp:attachment":[{"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diji.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}