{"id":419466,"date":"2021-03-30T16:18:26","date_gmt":"2021-03-30T08:18:26","guid":{"rendered":"http:\/\/4563.org\/?p=419466"},"modified":"2021-03-30T16:18:26","modified_gmt":"2021-03-30T08:18:26","slug":"jwilder-nginx-proxy-%e8%bf%99%e4%b8%aa%e9%95%9c%e5%83%8f%e6%98%af%e5%95%a5%e5%8e%9f%e7%90%86%e5%8f%af%e4%bb%a5%e5%8a%a8%e6%80%81%e8%ae%be%e7%bd%ae%e5%a4%9a%e5%9f%9f%e5%90%8d","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=419466","title":{"rendered":"jwilder\/nginx-proxy \u8fd9\u4e2a\u955c\u50cf\u662f\u5565\u539f\u7406\u53ef\u4ee5\u52a8\u6001\u8bbe\u7f6e\u591a\u57df\u540d"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  jwilder\/nginx-proxy \u8fd9\u4e2a\u955c\u50cf\u662f\u5565\u539f\u7406\u53ef\u4ee5\u52a8\u6001\u8bbe\u7f6e\u591a\u57df\u540d               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : dzdh <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>https:\/\/www.yannmoisan.com\/docker.html<\/p>\n<pre><code>docker run -d -p 80:80 -v \/var\/run\/docker.sock:\/tmp\/docker.sock:ro jwilder\/nginx-proxy docker run -d -e VIRTUAL_HOST=site1 ymn\/site1 docker run -d -e VIRTUAL_HOST=site2 ymn\/site2 <\/code><\/pre>\n<p>\u600e\u4e48\u5c31<code>nginx-proxy<\/code>\u5c31\u80fd\u83b7\u53d6\u5230 <code>site1.domain<\/code> \u7136\u540e\u5f53 <code>nginx-proxy<\/code>\u6536\u5230 80 \u7aef\u53e3\u8bf7\u6c42\u540e\u518d\u52a8\u6001\u8f6c\u53d1\u7ed9 <code>site<\/code> \u8fd9\u4e2a\u5bb9\u5668\u7684\uff1f<\/p>\n<p>\u5982\u679c\u4e0d\u7528\u8fd9\u79cd\u5f62\u5f0f\u7684\u8bdd\u3002\u662f\u4e0d\u662f\u5c31\u53ea\u80fd\u662f\u6539\u5bb9\u5668\u5185\u7684 nginx \u7684\u914d\u7f6e\u6587\u4ef6\uff1f<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>7<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5603577\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Tink <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u53cd\u5411\u4ee3\u7406\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5603578\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dzdh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Tink <\/p>\n<p>\u4e09\u4e2a\u9694\u79bb\u7684\u5bb9\u5668 proxy \u662f\u600e\u4e48\u77e5\u9053\u54ea\u4e2a domain \u300e\u7ed1\u300f\u5728\u54ea\u4e2a container \u4e0a\uff1f\u7aef\u53e3\u662f\u4ec0\u4e48\uff1f\u7136\u540e\u628a\u8bf7\u6c42\u53d1\u8fc7\u53bb\u7684                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5603579\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Tink <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dzdh \u8fd9\u660e\u663e\u662f\u8981\u914d\u7f6e\u7684\u554a\uff0c\u4f60\u770b\u6587\u7ae0\u554a                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5603580\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Tink <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @dzdh <\/p>\n<p>Let\u2019s create a new project, divided in 3 folders : site1, site2, proxy. One folder for each container.<\/p>\n<p>proxy<br \/> Dockerfile<br \/> conf<br \/> conf.d<br \/> site1.conf<br \/> site2.conf<br \/>site1<br \/> Dockerfile<br \/> index.html<br \/>site2<br \/> Dockerfile<br \/> index.html                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5603581\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : oott123 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4eba\u5bb6\u5199\u5f97\u5f88\u6e05\u695a\u2026<\/p>\n<p>Docker expose a remote API that allows to automate many tasks. So some projects leverage this API, like nginx-proxy which generate automatically the config of the proxy:                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5603582\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Kilerd <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u672c\u8d28\u4e0a\u8fd9\u4e2a\u5c31\u662f\u7528 docker-gen \u6765\u5b9e\u65f6\u8bfb\u53d6 docker container \u7684\u5217\u8868\uff0c\u7136\u540e\u7b5b\u9009\u51fa\u5e26 host \u6807\u7b7e\u7684 container\uff0c\u7136\u540e\u751f\u6210\u4e00\u4efd\u6700\u65b0\u7684 nginx.conf\uff0c\u7136\u540e\u6267\u884c nginx reload\uff0c \u5c31\u8fd9\u4e48\u7b80\u5355                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5603583\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : dzdh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @oott123 <br \/>@Kilerd <\/p>\n<p>\u597d\u7684\uff0c\u770b\u4e86 dockerfile\uff0c\u4f7f\u7528\u4e86 docker-gen\uff0c\u5b9a\u65f6\u5237 \u5171\u4eab\u7684 docker.sock \u8c03\u7528\u63a5\u53e3 \/containers\/json \u7136\u540e\u518d\u904d\u5386\u6240\u6709\u5bb9\u5668\u518d\u8c03\u7528 \/containers\/$containerId\/json \u518d\u83b7\u53d6 {{.Config.Env}} \u7136\u540e\u5237\u65b0 nginx \u914d\u7f6e\u6587\u4ef6<\/p>\n<p>\u5982\u679c\u4e0d\u7528\u8fd9\u79cd\u65b9\u6848\u662f\u4e0d\u662f\u5c31\u53ea\u80fd \u628a\u914d\u7f6e\u6587\u4ef6\u56fa\u5b9a\u5728\u955c\u50cf\u5185\u7136\u540e\u518d\u542f\u52a8 service \u4e86(swarm)                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>jwilder\/nginx-pro&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/419466"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=419466"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/419466\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=419466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=419466"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=419466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}