{"id":24560215,"url":"https://github.com/fh332393900/docker-compose-node","last_synced_at":"2026-05-04T09:33:17.102Z","repository":{"id":106250836,"uuid":"585861080","full_name":"fh332393900/docker-compose-node","owner":"fh332393900","description":"📦 docker-compose实现node服务代理到二级路径","archived":false,"fork":false,"pushed_at":"2023-01-06T10:00:54.000Z","size":24,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-19T22:15:24.747Z","etag":null,"topics":["docker","docker-compose","node"],"latest_commit_sha":null,"homepage":"https://fh332393900.github.io/Docker/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fh332393900.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-06T09:24:01.000Z","updated_at":"2023-03-04T18:06:21.000Z","dependencies_parsed_at":"2023-03-13T14:40:36.501Z","dependency_job_id":null,"html_url":"https://github.com/fh332393900/docker-compose-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fh332393900/docker-compose-node","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fh332393900%2Fdocker-compose-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fh332393900%2Fdocker-compose-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fh332393900%2Fdocker-compose-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fh332393900%2Fdocker-compose-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fh332393900","download_url":"https://codeload.github.com/fh332393900/docker-compose-node/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fh332393900%2Fdocker-compose-node/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32601547,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T22:12:39.696Z","status":"online","status_checked_at":"2026-05-04T02:00:06.625Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","node"],"created_at":"2025-01-23T07:16:09.567Z","updated_at":"2026-05-04T09:33:17.096Z","avatar_url":"https://github.com/fh332393900.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"📦 *docker-compose* 实现 node 服务代理到二级路径\n\n使用 `docker-compose` 运行容器，同时部署 node 版与 nginx 版\n\n## 使用方法\n``` bash\n$ docker-compose up --build\n```\n\n### 前言（背景）\n\n我们在服务器运行了一个 Node 服务端口在 `3000`，我们要访问服务的接口就只能在 http://xxx:3000 进行访问\n但是我们想直接在 `80` 端口进行访问，例如 http://xxx/api 来调用接口要怎么做呢？\n\n### 实现\n\n我们可以使用 nginx 来配置把端口代理到二级路径实现\n\n```js\nserver {\n    listen       80;\n    server_name  localhost;\n\n    root   /usr/share/nginx/html;\n    index  index.html index.htm;\n\n    location /api {\n        add_header X-Config A;\n        proxy_pass http://47.108.210.87:3000;\n    }\n}\n```\n\ndocker-componse 的配置\n\n```yaml\nversion: \"3\"\nservices:\n  node-app:\n    build:\n      context: .\n      dockerfile: node.Dockerfile\n    ports:\n      - 3000:3000\n  nginx-app:\n    build:\n      context: .\n      dockerfile: nginx.Dockerfile\n    ports:\n      - 80:80\n    volumes:\n      - ./proxy.conf:/etc/nginx/conf.d/default.conf\n      - .:/usr/share/nginx/html\n```\n\n说明：\n我们的 node 服务是运行在 3000 端口的，在 80 端口是我们的前端页面，同时添加代理的配置\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffh332393900%2Fdocker-compose-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffh332393900%2Fdocker-compose-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffh332393900%2Fdocker-compose-node/lists"}