{"id":20,"date":"2026-11-08T13:15:51","date_gmt":"2026-11-08T13:15:51","guid":{"rendered":"http:\/\/blog.antpython.net\/?p=20"},"modified":"2026-11-08T13:15:51","modified_gmt":"2026-11-08T13:15:51","slug":"nginx-%e5%8f%8d%e5%90%91%e4%bb%a3%e7%90%86%e4%b8%8e-docker-%e9%83%a8%e7%bd%b2-web-%e5%ba%94%e7%94%a8%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"http:\/\/blog.antpython.net\/?p=20","title":{"rendered":"Nginx \u53cd\u5411\u4ee3\u7406\u4e0e Docker \u90e8\u7f72 Web \u5e94\u7528\u5165\u95e8"},"content":{"rendered":"<p>\u672c\u5730 <code>python app.py<\/code> \u80fd\u8dd1\uff0c\u4e0d\u4ee3\u8868\u80fd\u4e0a\u7ebf\u3002\u751f\u4ea7\u73af\u5883\u901a\u5e38\u662f\uff1a<strong>Docker \u8dd1\u5e94\u7528 + Nginx \u5bf9\u5916\u53cd\u4ee3<\/strong>\u3002\u672c\u6587\u7ed9\u4f60\u6700\u5c0f\u53ef\u7528\u56fe\u666f\u3002<\/p>\n<h2>\u4e3a\u4ec0\u4e48\u9700\u8981 Nginx<\/h2>\n<ul>\n<li>\u7edf\u4e00 80\/443 \u5165\u53e3\uff0c\u540e\u7aef\u4e0d\u76f4\u63a5\u66b4\u9732<\/li>\n<li>\u9759\u6001\u8d44\u6e90\u7f13\u5b58\u3001HTTPS \u7ec8\u7ed3<\/li>\n<li>\u591a\u670d\u52a1\u6309\u57df\u540d\/\u8def\u5f84\u5206\u6d41<\/li>\n<\/ul>\n<h2>\u53cd\u5411\u4ee3\u7406\u7247\u6bb5<\/h2>\n<pre><code>server {\n    listen 80;\n    server_name demo.example.com;\n\n    location \/ {\n        proxy_pass http:\/\/webapp:8000;\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}\n<\/code><\/pre>\n<h2>Docker Compose \u601d\u8def<\/h2>\n<pre><code>services:\n  webapp:\n    build: .\n    networks: [app-net]\n  nginx:\n    image: nginx:1.25-alpine\n    ports: [\"80:80\"]\n    volumes:\n      - .\/nginx.conf:\/etc\/nginx\/conf.d\/default.conf:ro\n    depends_on: [webapp]\n    networks: [app-net]\n<\/code><\/pre>\n<h2>\u4e0a\u7ebf\u68c0\u67e5\u6e05\u5355<\/h2>\n<ol>\n<li>\u5065\u5eb7\u68c0\u67e5\u63a5\u53e3\uff1a<code>\/health<\/code><\/li>\n<li>\u65e5\u5fd7\u843d\u76d8\u6216\u6536\u96c6\uff0c\u65b9\u4fbf\u6392\u9519<\/li>\n<li>\u5bc6\u94a5\u8d70\u73af\u5883\u53d8\u91cf<\/li>\n<li>\u6570\u636e\u5e93\u4e0d\u6620\u5c04\u516c\u7f51\u7aef\u53e3<\/li>\n<\/ol>\n<p>\u4f60\u73b0\u5728\u7684 <a href=\"http:\/\/antpython.net\/\">antpython.net<\/a> \u4e0e\u535a\u5ba2\uff0c\u5c31\u662f\u300c\u540c\u7f51\u6865 + Nginx \u6309\u57df\u540d\u53cd\u4ee3\u300d\u7684\u5178\u578b\u7ed3\u6784\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u5730 python app.py \u80fd\u8dd1\uff0c\u4e0d\u4ee3\u8868\u80fd\u4e0a\u7ebf\u3002\u751f\u4ea7\u73af\u5883\u901a\u5e38\u662f\uff1aDocker \u8dd1\u5e94\u7528 + Nginx \u5bf9 [&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-20","post","type-post","status-publish","format-standard","hentry","category-web-development"],"_links":{"self":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts\/20","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=20"}],"version-history":[{"count":0,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=\/wp\/v2\/posts\/20\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.antpython.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}