{"id":353,"date":"2025-11-18T00:09:33","date_gmt":"2025-11-17T16:09:33","guid":{"rendered":"https:\/\/halouman.top\/?p=353"},"modified":"2025-11-27T09:29:00","modified_gmt":"2025-11-27T01:29:00","slug":"%e9%80%9a%e8%bf%87nginx%e7%bb%99web%e6%9c%8d%e5%8a%a1%e5%a2%9e%e5%8a%a0%e7%99%bb%e5%bd%95%e9%aa%8c%e8%af%81","status":"publish","type":"post","link":"https:\/\/halouman.top\/?p=353","title":{"rendered":"\u901a\u8fc7Nginx\u7ed9web\u670d\u52a1\u589e\u52a0\u767b\u5f55\u9a8c\u8bc1"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"346\" src=\"https:\/\/halouman.top\/wp-content\/uploads\/2025\/11\/ScreenShot_2025-11-20_225227_594.png\" alt=\"\" class=\"wp-image-378\" srcset=\"https:\/\/halouman.top\/wp-content\/uploads\/2025\/11\/ScreenShot_2025-11-20_225227_594.png 602w, https:\/\/halouman.top\/wp-content\/uploads\/2025\/11\/ScreenShot_2025-11-20_225227_594-300x172.png 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u9636\u6bb5<\/th><th>\u5173\u952e\u4efb\u52a1<\/th><th>\u8bf4\u660e\/\u907f\u5751\u8981\u70b9<\/th><\/tr><\/thead><tbody><tr><td><strong>1. \u51c6\u5907\u9879\u76ee\u76ee\u5f55<\/strong><\/td><td>\u521b\u5efa\u6e05\u6670\u7684\u6587\u4ef6\u7ed3\u6784<\/td><td>\u907f\u514d\u6743\u9650\u548c\u8def\u5f84\u9519\u8bef\u7684\u57fa\u7840\u3002<\/td><\/tr><tr><td><strong>2. \u914d\u7f6e\u8ba4\u8bc1\u6587\u4ef6<\/strong><\/td><td>\u521b\u5efa<code>.htpasswd<\/code>\u5bc6\u7801\u6587\u4ef6<\/td><td>\u786e\u4fdd\u5bc6\u7801\u6587\u4ef6\u683c\u5f0f\u6b63\u786e\uff0c\u5e76\u6ce8\u610f\u5728\u56fe\u5f62\u754c\u9762\u4e2d\u6b63\u786e\u8bbe\u7f6e\u6587\u4ef6\u6743\u9650\u3002<\/td><\/tr><tr><td><strong>3. \u7f16\u5199Docker Compose\u6587\u4ef6<\/strong><\/td><td>\u5b9a\u4e49\u670d\u52a1\u3001\u7f51\u7edc\u3001\u6302\u8f7d\u5377<\/td><td>\u8fd9\u662f\u6838\u5fc3\u914d\u7f6e\u6587\u4ef6\uff0c\u786e\u4fdd\u8bed\u6cd5\u548c\u7f29\u8fdb\u6b63\u786e\u3002<\/td><\/tr><tr><td><strong>4. \u914d\u7f6eNginx<\/strong><\/td><td>\u7f16\u5199<code>nginx.conf<\/code>\u548c\u670d\u52a1\u5668\u914d\u7f6e<\/td><td>\u6b63\u786e\u8bbe\u7f6e\u4e0a\u6e38\u670d\u52a1\u3001\u8ba4\u8bc1\u3001\u6587\u4ef6\u5927\u5c0f\u9650\u5236\u3002<\/td><\/tr><tr><td><strong>5. \u98de\u725bNAS\u90e8\u7f72<\/strong><\/td><td>\u5728\u56fe\u5f62\u754c\u9762\u521b\u5efaCompose\u9879\u76ee<\/td><td>\u786e\u4fdd\u9009\u62e9\u6b63\u786e\u7684\u9879\u76ee\u8def\u5f84\u548cCompose\u6587\u4ef6\u3002<\/td><\/tr><tr><td><strong>6. \u9a8c\u8bc1\u4e0e\u6d4b\u8bd5<\/strong><\/td><td>\u68c0\u67e5\u5bb9\u5668\u72b6\u6001\u3001\u6d4b\u8bd5\u8bbf\u95ee\u548c\u4e0a\u4f20<\/td><td>\u901a\u8fc7\u65e5\u5fd7\u6392\u67e5\u95ee\u9898\uff0c\u786e\u4fdd\u5404\u9879\u529f\u80fd\u6b63\u5e38\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u7b2c\u4e00\u6b65\uff1a\u51c6\u5907\u9879\u76ee\u7ed3\u6784\u4e0e\u6587\u4ef6<\/h3>\n\n\n\n<p>\u5728\u98de\u725bNAS\u4e0a\u521b\u5efa\u4e00\u4e2a\u72ec\u7acb\u7684\u9879\u76ee\u76ee\u5f55\uff0c\u4f8b\u5982 <code>nginx_gateway<\/code>\u3002\u63a8\u8350\u7684\u6587\u4ef6\u7ed3\u6784\u5982\u4e0b\uff0c\u8fd9\u6709\u52a9\u4e8e\u6e05\u6670\u7ba1\u7406\u914d\u7f6e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>\/nginx<em>_gateway\/\n\u251c\u2500\u2500 docker-compose.yml       # Docker Compose \u7f16\u6392\u6587\u4ef6\n\u251c\u2500\u2500 nginx\/\n\u2502   \u251c\u2500\u2500 nginx.conf           # Nginx \u4e3b\u914d\u7f6e\u6587\u4ef6\n\u2502   \u2514\u2500\u2500 conf.d\/              # (\u53ef\u9009) \u53ef\u7528\u4e8e\u5b58\u653e\u5176\u4ed6\u914d\u7f6e\u7247\u6bb5\n<code><em>\u2514<\/em><em style=\"font-family: inherit; font-size: inherit; text-align: initial;\">\u2500\u2500 auth\/<\/em><\/code>      \u2514\u2500\u2500 .htpasswd            # \u5b58\u50a8\u7528\u6237\u540d\u548c\u5bc6\u7801\u7684\u8ba4\u8bc1\u6587\u4ef6\n<\/em><\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd10 \u7b2c\u4e8c\u6b65\uff1a\u914d\u7f6e\u8ba4\u8bc1\u6587\u4ef6<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u751f\u6210 .htpasswd \u6587\u4ef6<\/strong>\uff1a\u4f7f\u7528 <a href=\"https:\/\/tool.oschina.net\/htpasswd\" data-type=\"link\" data-id=\"https:\/\/tool.oschina.net\/htpasswd\">\u5728\u7ebfhtpasswd\u5de5\u5177<\/a>\u3002\u8f93\u5165\u7528\u6237\u540d\u4e3a\u548c\u79d8\u5bc6\uff0c\u70b9\u51fb\u751f\u6210\uff0c\u751f\u6210\u7684\u7ed3\u679c\u590d\u5236\u5230\u6587\u672c\u91cc\uff0c\u628a\u6587\u672c\u91cd\u547d\u540d\u4e3a\uff1a<strong>.htpasswd<\/strong><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"534\" height=\"342\" src=\"https:\/\/halouman.top\/wp-content\/uploads\/2025\/11\/\u751f\u6210\u5bc6\u7801.png\" alt=\"\" class=\"wp-image-357\" srcset=\"https:\/\/halouman.top\/wp-content\/uploads\/2025\/11\/\u751f\u6210\u5bc6\u7801.png 534w, https:\/\/halouman.top\/wp-content\/uploads\/2025\/11\/\u751f\u6210\u5bc6\u7801-300x192.png 300w\" sizes=\"auto, (max-width: 534px) 100vw, 534px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u8bbe\u7f6e\u6587\u4ef6\u6743\u9650\uff08\u5173\u952e\uff01\uff09<\/strong>\uff1a\u8bbe\u7f6e <code>auth<\/code>\u6587\u4ef6\u5939\u6743\u9650\uff0c\u786e\u4fdd\u6587\u4ef6\u6240\u6709\u8005\u6709\u8bfb\u5199\u6743\u9650\uff0c\u6216\u76f4\u63a5\u8bbe\u7f6e\u4e3a <code>101:101<\/code>\uff08Nginx\u5bb9\u5668\u5185\u5e38\u7528\u7684\u7528\u6237ID\u548c\u7ec4ID\uff09\uff0c\u4ee5\u907f\u514dNginx\u8fdb\u7a0b\u65e0\u6743\u9650\u8bfb\u53d6\u5bc6\u7801\u6587\u4ef6\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u8fde\u63a5\u5230\u98de\u725bNAS\u7684SSH<\/strong>\uff1a\u4f7f\u7528\u5982Terminal\uff08macOS\/Linux\uff09\u6216PuTTY\uff08Windows\uff09\u7b49\u5de5\u5177\uff0c\u901a\u8fc7\u7ba1\u7406\u5458\u8d26\u6237SSH\u767b\u5f55\u5230\u4f60\u7684\u98de\u725bNAS\u3002\u5730\u5740\u662f\u4f60\u7684NAS IP\uff0c\u7aef\u53e3\u901a\u5e38\u662f22\u3002<\/p>\n\n\n\n<p><strong>\u5bfc\u822a\u5230\u9879\u76ee\u76ee\u5f55<\/strong>\uff1a\u4f7f\u7528 <code>cd<\/code>\u547d\u4ee4\u8fdb\u5165\u4f60\u5b58\u653e <code>auth<\/code>\u6587\u4ef6\u5939\u7684\u8def\u5f84\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/path\/to\/your\/nginx_gateway<\/code><\/pre>\n\n\n\n<p><strong>\u9012\u5f52\u4fee\u6539\u6240\u6709\u8005<\/strong>\uff1a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5c06<code>auth<\/code>\u76ee\u5f55\u53ca\u5176\u5185\u90e8\u6240\u6709\u6587\u4ef6\u7684\u6240\u6709\u8005\u548c\u7ec4\u90fd\u6539\u4e3aUID 101\u548cGID 101\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chown -R 101:101 auth\/<\/code><\/pre>\n\n\n\n<p><strong>\u9012\u5f52\u4fee\u6539\u6587\u4ef6\u6743\u9650<\/strong>\uff1a\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u786e\u4fdd\u6743\u9650\u6b63\u786e\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chmod -R 755 auth\/<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udc33 \u7b2c\u4e09\u6b65\uff1a\u7f16\u5199 Docker Compose \u6587\u4ef6<\/h3>\n\n\n\n<p>\u4ee5\u4e0b\u662f <code>docker-compose.yml<\/code>\u6587\u4ef6\u7684\u5185\u5bb9<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>\nservices:\n  nginx-gateway:\n    image: nginx:latest\n    container_name: nginx-gateway\n    ports:\n      - \"8080:80\"  <em># \u5c06NAS\u76848080\u7aef\u53e3\u6620\u5c04\u5230Nginx\u5bb9\u5668\u768480\u7aef\u53e3<\/em>\n    volumes:\n      <em># \u6302\u8f7dNginx\u914d\u7f6e\u6587\u4ef6<\/em>\n      - \/vol1\/1000\/docker\/nginx_gateway\/nginx\/nginx.conf:\/etc\/nginx\/nginx.conf:ro\n      <em># \u6302\u8f7d\u8ba4\u8bc1\u6587\u4ef6<\/em>\n      - \/vol1\/1000\/docker\/<span style=\"background-color: rgba(255, 102, 142, 0.09); font-family: inherit; font-size: inherit; text-align: initial;\">nginx_<\/span>gateway\/auth\/.htpasswd:\/etc\/nginx\/auth\/.htpasswd:ro\n\n    network_mode: bridge\n    restart: unless-stopped  <em># \u5bb9\u5668\u5f02\u5e38\u9000\u51fa\u65f6\u81ea\u52a8\u91cd\u542f<\/em>\n\n<\/code><\/code><\/pre>\n\n\n\n<p><strong>\u91cd\u8981\u63d0\u793a<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6302\u8f7d\u5377\u7684\u8def\u5f84\uff08\u5982 <code>\/vol1\/1000\/docker\/nginx_gateway<\/code>\uff09\u9700\u8981\u66ff\u6362\u4e3a\u4f60\u5728\u98de\u725bNAS\u4e0a\u7684<strong>\u5b9e\u9645\u7edd\u5bf9\u8def\u5f84<\/strong>\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u2699\ufe0f \u7b2c\u56db\u6b65\uff1a\u914d\u7f6e Nginx<\/h3>\n\n\n\n<p>\u521b\u5efa <code>nginx\/nginx.conf<\/code>\u6587\u4ef6\uff0c\u4ee5\u4e0b\u662f\u6838\u5fc3\u914d\u7f6e\uff0c\u5b83\u89e3\u51b3\u4e86\u4ee3\u7406\u8bbe\u7f6e\u3001\u8ba4\u8bc1\u3001\u6587\u4ef6\u4e0a\u4f20\u5927\u5c0f\u9650\u5236\u95ee\u9898<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>user  nginx;\nevents {\n    worker_connections  1024;\n}\n\nhttp {\n    include       \/etc\/nginx\/mime.types;\n    default_type  application\/octet-stream;\n    sendfile        on;\n    keepalive_timeout  65;\n\n    # \u8bbe\u7f6e\u5ba2\u6237\u7aef\u6700\u5927\u8bf7\u6c42\u4f53\u5927\u5c0f\uff0c\u89e3\u51b3\u5927\u6587\u4ef6\u4e0a\u4f20\u95ee\u9898\n    client_max_body_size 20M;\n\n    # \u5b9a\u4e49\u4e0a\u6e38\u670d\u52a1\u5668\uff08\u4f60\u7684\u670b\u53cb\u5708\u5e94\u7528\uff09\n    upstream moments_app {\n        server moments:3000; # \u4f7f\u7528Docker Compose\u670d\u52a1\u540d\"moments\"\u8fdb\u884c\u5185\u90e8\u901a\u4fe1\n    }\n\n    server {\n        listen 80;\n        server_name localhost;\n\n        # \u542f\u7528\u57fa\u7840\u8ba4\u8bc1\n        auth_basic \"Restricted Content\";\n        auth_basic_user_file \/etc\/nginx\/auth\/.htpasswd;\n\n        location \/ {\n            # \u4ee3\u7406\u5230\u670b\u53cb\u5708\u5e94\u7528\n            proxy_pass http:\/\/moments_app; # \u8bf7\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u4fee\u6539\u5bb9\u5668\u540d\u548c\u7aef\u53e3\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\n\n\n<h3 class=\"wp-block-heading\">\ud83d\ude80 \u7b2c\u4e94\u6b65\uff1a\u5728\u98de\u725bNAS\u4e0a\u90e8\u7f72<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>1.1.\u6253\u5f00\u98de\u725bNAS\u7684Docker\u7ba1\u7406\u754c\u9762\u3002<\/li>\n\n\n\n<li>2.2.\u8fdb\u5165 <strong>Compose<\/strong>\u200b \u6807\u7b7e\u9875\uff0c\u70b9\u51fb <strong>\u65b0\u589e\u9879\u76ee<\/strong>\u3002<\/li>\n\n\n\n<li>3.3.\u586b\u5199\u9879\u76ee\u540d\u79f0\uff08\u5982 <code><code>nginx_gateway<\/code><\/code>\uff09\u3002<\/li>\n\n\n\n<li>4.4.\u5728\u201c\u8def\u5f84\u201d\u4e2d\u9009\u62e9\u4f60\u521b\u5efa\u7684\u9879\u76ee\u6839\u76ee\u5f55\uff08<code>nginx_gateway<\/code>\uff09\u3002<\/li>\n\n\n\n<li>5.5.\u5728\u201c\u6765\u6e90\u201d\u90e8\u5206\uff0c\u9009\u62e9\u201c\u4e0a\u4f20docker-compose.yml\u201d\uff0c\u7136\u540e\u9009\u62e9\u4f60\u7f16\u8f91\u597d\u7684 <code>docker-compose.yml<\/code>\u6587\u4ef6\u3002<\/li>\n\n\n\n<li>6.6.\u786e\u8ba4\u52fe\u9009\u201c\u521b\u5efa\u540e\u7acb\u5373\u542f\u52a8\u201d\uff0c\u7136\u540e\u70b9\u51fb\u201c\u786e\u5b9a\u201d\u3002\u98de\u725bNAS\u5c06\u81ea\u52a8\u62c9\u53d6\u955c\u50cf\u5e76\u542f\u52a8\u5bb9\u5668\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 \u7b2c\u516d\u6b65\uff1a\u9a8c\u8bc1\u4e0e\u6d4b\u8bd5<\/h3>\n\n\n\n<p>\u90e8\u7f72\u5b8c\u6210\u540e\uff0c\u8fdb\u884c\u4ee5\u4e0b\u68c0\u67e5\u4ee5\u786e\u4fdd\u4e00\u5207\u6b63\u5e38\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>1.1.<strong>\u68c0\u67e5\u5bb9\u5668\u72b6\u6001<\/strong>\uff1a\u5728\u98de\u725bNAS\u7684Docker\u7ba1\u7406\u754c\u9762\uff0c\u67e5\u770b\u4e24\u4e2a\u5bb9\u5668\u7684\u72b6\u6001\u662f\u5426\u4e3a\u201c\u5df2\u542f\u52a8\u201d\u3002<\/li>\n\n\n\n<li>2.2.<strong>\u6d4b\u8bd5\u8ba4\u8bc1<\/strong>\uff1a\u5728\u6d4f\u89c8\u5668\u8bbf\u95ee <code>http:\/\/\u4f60\u7684\u98de\u725bNAS\u7684IP:8080<\/code>\u3002\u5e94\u8be5\u4f1a\u5f39\u51fa\u767b\u5f55\u6846\uff0c\u8f93\u5165\u6b63\u786e\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u540e\u624d\u80fd\u770b\u5230\u670b\u53cb\u5708\u5185\u5bb9\u3002<\/li>\n\n\n\n<li>3.3.<strong>\u6d4b\u8bd5\u56fe\u7247\u4e0a\u4f20<\/strong>\uff1a\u6210\u529f\u767b\u5f55\u540e\uff0c\u5c1d\u8bd5\u4e0a\u4f20\u4e00\u5f20\u56fe\u7247\uff0c\u786e\u8ba4\u529f\u80fd\u6b63\u5e38\u3002<\/li>\n\n\n\n<li>4.4.<strong>\u67e5\u770b\u65e5\u5fd7<\/strong>\uff1a\u5982\u679c\u9047\u5230\u95ee\u9898\uff0c\u9996\u5148\u67e5\u770b\u5bb9\u5668\u65e5\u5fd7\u3002\u5728\u98de\u725bDocker\u754c\u9762\u70b9\u51fb\u5bb9\u5668\u540d\u79f0\uff0c\u8fdb\u5165\u201c\u65e5\u5fd7\u201d\u6807\u7b7e\u9875\uff0c\u67e5\u770bNginx\u548c\u670b\u53cb\u5708\u5e94\u7528\u7684\u9519\u8bef\u4fe1\u606f\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\"><\/h3>\n","protected":false},"excerpt":{"rendered":"<p>\u9636\u6bb5 \u5173\u952e\u4efb\u52a1 \u8bf4\u660e\/\u907f\u5751\u8981\u70b9&hellip;<\/p>\n","protected":false},"author":1,"featured_media":378,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-353","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-6"],"_links":{"self":[{"href":"https:\/\/halouman.top\/index.php?rest_route=\/wp\/v2\/posts\/353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/halouman.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/halouman.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/halouman.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/halouman.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=353"}],"version-history":[{"count":15,"href":"https:\/\/halouman.top\/index.php?rest_route=\/wp\/v2\/posts\/353\/revisions"}],"predecessor-version":[{"id":380,"href":"https:\/\/halouman.top\/index.php?rest_route=\/wp\/v2\/posts\/353\/revisions\/380"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/halouman.top\/index.php?rest_route=\/wp\/v2\/media\/378"}],"wp:attachment":[{"href":"https:\/\/halouman.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/halouman.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/halouman.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}