{"id":1389,"date":"2025-05-03T05:55:25","date_gmt":"2025-05-03T05:55:25","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=1389"},"modified":"2025-05-03T11:34:43","modified_gmt":"2025-05-03T11:34:43","slug":"nginx-webnodejs-webantmedia-https","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2025\/05\/03\/nginx-webnodejs-webantmedia-https\/","title":{"rendered":"Nginx Web Server+Nodejs Https proxy +Antmedia Https proxy"},"content":{"rendered":"\n<p>&#8212; \uc544\ub798\ub294 nginx\ub97c \uc6f9\uc11c\ubc84\ub85c \uc0ac\uc6a9\ud558\uace0 nodejs https \ud504\ub85d\uc2dc Andmedia server \uc758 https\ud504\ub85d\uc2dc\ud558\ub294 \uc124\uc815\uc785\ub2c8\ub2e4.<br>Below is the configuration for using nginx as a web server and nodejs https proxy Andmedia server&#8217;s https proxy.<\/p>\n\n\n\n<p>https:\/\/host.domain.com\/nodejs\/ \u2192 Node.js \uc11c\ubc84 (\/nodejs\/)\ub97c \ud1b5\ud574 \uc811\uc18d\ud588\uc2b5\ub2c8\ub2e4. \/ You are accessing the Node.js server (\/nodejs\/).<\/p>\n\n\n\n<p>https:\/\/host.domain.com\/nodejs\/login \u2192 Node.js \uc11c\ubc84 (\/nodejs\/login)\ub97c \ud1b5\ud574 \uc811\uc18d\ud588\uc2b5\ub2c8\ub2e4. \/ You connected via the Node.js server (\/nodejs\/login).<\/p>\n\n\n\n<p>https:\/\/host.domain.com\/web\/ \u2192 \uc815\uc801 \ud30c\uc77c(index.html) \/ Static file(index.html)<\/p>\n\n\n\n<p>https:\/\/host.domain.com\/LiveApp\/ \u2192 Ant Media Server<\/p>\n\n\n\n<p>-Nginx\uc758 \ub8e8\ud2b8 \ub514\ub809\ud1a0\ub9ac \ucc98\ub9ac\uac00 Nodejs\ubcf4\ub2e4  \uba3c\uc800 \uc2e4\ud589\ub418\ubbc0\ub85c \uc124\uc815\uc774 \uc911\ubcf5\ub418\uba74 nodejs &#8216;\/&#8217; \ub294\uc2e4\ud589\uc774 \uc548\ub429\ub2c8\ub2e4.<br>Since Nginx&#8217;s root directory processing is executed before Nodejs, if the settings are duplicated, nodejs &#8216;\/&#8217; will not be executed.<\/p>\n\n\n\n<p>-nodejs\uad6c\uc131\uc2dc \/nodejs\/\ucc98\ub7fc \ub77c\uc6b0\ud130\uc5d0 \uc811\ub450\uc5b4\ub97c \ub2e4 \ubd99\uc5ec\uc11c \uad6c\uc131\ud558\ub294 \uac83\uc744 \ucd94\ucc9c\ud569\ub2c8\ub2e4.(\ub8e8\ud2b8\ub85c \uc2e4\ud589\uc2dc nginx\ucc98\ub9ac\uac00 \uc6b0\uc120\uc774\ubbc0\ub85c \uc2e4\ud589 \ub418\uc9c0 \uc54a\uc744 \uc218 \uc788\uc74c)<br>When configuring nodejs, it is recommended to configure it by adding a prefix to the router, such as \/nodejs\/. (When running as root, nginx processing takes priority, so it may not run.)<\/p>\n\n\n\n<p>-\uc694\uccad \ucc98\ub9ac \uc124\uba85 \/ Request Processing Description<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\uc694\uccad \uacbd\ub85c<br>request path<\/th><th>\ucc98\ub9ac\uc8fc\uccb4<br>Processing entity<\/th><th>\uc124\uba85 <br>explanation<\/th><\/tr><\/thead><tbody><tr><td><code>\/<\/code><\/td><td>Nginx<\/td><td>\uc815\uc801 \ud30c\uc77c <code>\/var\/www\/html\/index.html<\/code> \uc81c\uacf5<br>Static file \/var\/www\/html\/index.html<\/td><\/tr><tr><td><code>\/nodejs\/<\/code><\/td><td>Node.js<\/td><td>Nginx\uac00 \ud504\ub85d\uc2dc\ub85c \uc804\ub2ec<br>Nginx proxying<\/td><\/tr><tr><td><code>\/LiveApp\/<\/code><\/td><td>Ant Media<\/td><td>Nginx\uac00 \ud504\ub85d\uc2dc\ub85c \uc804\ub2ec<br>Nginx proxying<\/td><\/tr><tr><td>\uae30\ud0c0 etc<\/td><td>Nginx<\/td><td><code>try_files<\/code>\ub85c \uc815\uc801 \ud30c\uc77c \ud655\uc778 \ud6c4 \uc5c6\uc73c\uba74 404<br>Check static files with try_files and output 404<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>&#8212; Nginx location \/nodejs\/ + proxy_pass http:\/\/localhost:3000\/nodejs\/;<br>Nginx\ub294 \uc694\uccad \uacbd\ub85c\uc5d0\uc11c location \/nodejs\/ \uc774\ud6c4\uc758 \uacbd\ub85c(\uc989, \/admin)\ub97c \uc798\ub77c\uc11c proxy_pass \ub4a4\uc5d0 \ubd99\uc785\ub2c8\ub2e4.<br>Nginx will cut off the path after location \/nodejs\/ ( \/admin ) from the request path and append it after proxy_pass.<br>\ud558\uc9c0\ub9cc proxy_pass\uc5d0 \uc2ac\ub798\uc2dc\ub85c \ub05d\ub098\ub294 \uacbd\ub85c\uac00 \uc788\uc73c\uba74, \uc798\ub9b0 \uacbd\ub85c\ub97c \uadf8\ub300\ub85c \ubd99\uc5ec\uc11c \uc804\ub2ec\ud569\ub2c8\ub2e4.<br>However, if proxy_pass contains a path that ends with a slash, the truncated path is passed as is<br><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>\uc694\uccad: https:\/\/host.damain.com\/nodejs\/admin\nlocation: \/nodejs\/\nproxy_pass: http:\/\/localhost:3000\/nodejs\/\n\n\u2192 \uc804\ub2ec: http:\/\/localhost:3000\/nodejs\/admin\n\nNode.js\ub294 \uadf8\ub0e5 \uc815\uc0c1\uc801\uc778 \/nodejs\/admin \uacbd\ub85c\ub97c \ubc1b\uac8c \ub429\ub2c8\ub2e4.\n\nNginx(\/etc\/nginx\/sites-available\/default) \uc124\uc815<\/strong><\/pre>\n\n\n\n<p>&#8212; \uadf8\ub7f0\ub370 \ub9cc\uc57d proxy_pass\uac00 \uc2ac\ub798\uc2dc \uc5c6\uc774 \ub05d\ub09c\ub2e4\uba74?<br>But what if proxy_pass ends without a slash?<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">proxy_pass http:\/\/localhost:3000\/nodejs;   # \uc2ac\ub798\uc2dc \uc5c6\uc74c \/ no slash\n<\/pre>\n\n\n\n<p>\uc774\ub7f4 \uacbd\uc6b0 Nginx\ub294 \uc694\uccad \uacbd\ub85c \uc804\uccb4\ub97c proxy_pass\uc758 \ub4a4\uc5d0 \ubd99\uc774\uc9c0 \uc54a\uace0, \uadf8\ub0e5 \ub36e\uc5b4\uc50c\uc6c1\ub2c8\ub2e4.<br>In this case, Nginx will not append the entire request path to proxy_pass, but will simply overwrite it.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">https:\/\/\u2026\/nodejs\/admin \u2192 http:\/\/localhost:3000\/nodejsadmin<\/pre>\n\n\n\n<p>&#8212; \uacb0\ub860\uc740 nginx\uc5d0\uc11c \uacbd\ub85c \uc124\uc815\uc744 \uc62c\ubc14\ub85c \ud558\uba74 \ud504\ub85d\uc2dc\ub41c \uacb0\uacfc\uac12(http:\/\/localhost:3000\/nodejs\/admin)\uc744 \uac00\uc9c0\uace0 nodejs\uc5d0\uc11c \uacb0\uacfc\uac12\uc744 \ucc98\ub9ac\ud569\ub2c8\ub2e4.<br>The bottom line is that if you set the path correctly in nginx, the proxied result (http:\/\/localhost:3000\/nodejs\/admin) will be used to process the result in nodejs.<\/p>\n\n\n\n<p>-\ub9c8\uc9c0\ub9c9\uc73c\ub85c \uc815\ub9ac\ud558\uc790\uba74&#8230;<br>Finally, to summarize<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">1.nginx\uc758 \uc124\uc815\uc774 nodejs\ubcf4\ub2e4 \uc6b0\uc120\uc21c\uc704\uac00 \ub192\ub2e4. \uadf8\ub7ec\ubbc0\ub85cnodejs\ub97c \ub8e8\ud2b8(\/)\ub77c\uc6b0\ud130\ub97c \uc0ac\uc6a9\ud558\uba74 \uc624\ub958\uac00 \ubc1c\uc0dd \ud560 \uc218 \uc788\ub2e4.\n2.nginx \uc124\uc815\uc758 proxy_pass http:\/\/localhost:3000\/nodejs\/;\uc5d0\uc11c \ub9c8\uc9c0\ub9c9 \/ \uac00 \uc911\uc694\ud558\ub2e4.\n3.nginx\uc124\uc815\uc774 \uc62c\ubc14\ub974\ub2e4\uba74 nodejs\ub294 nginx\ub97c \ubaa8\ub974\ub2c8 \ud504\ub85d\uc2dc \ucc98\ub9ac\ub41c \ubd80\ubd84\uc758 \ub77c\uc6b0\ud130 \ubd80\ubd84\ub9cc \ucc98\ub9ac\ud55c\ub2e4.<\/pre>\n\n\n\n<p><strong>2.\uc124\uc815 \ubc0f \uc18c\uc2a4\ucf54\ub4dc<\/strong><\/p>\n\n\n\n<p>&#8212;<strong> Nginx(\/etc\/nginx\/sites-available\/default) Setting<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen 443 ssl;\n    server_name host.domain.com;\n\n    ssl_certificate \/etc\/letsencrypt\/live\/media.freelifemakers.org\/fullchain.pem;\n    ssl_certificate_key \/etc\/letsencrypt\/live\/media.freelifemakers.org\/privkey.pem;\n    include \/etc\/letsencrypt\/options-ssl-nginx.conf;\n    ssl_dhparam \/etc\/letsencrypt\/ssl-dhparams.pem;\n\n    # \uc815\uc801 \uc6f9 \ud30c\uc77c \/ static web files (\/web\/)\n    location \/web\/ {\n        alias \/var\/www\/html\/web\/;\n        index index.html;\n        try_files $uri $uri\/ =404;\n    }\n\n    # Ant Media Server \uc5f0\ub3d9 \/ antmedia server integration (\/LiveApp\/)\n    location \/LiveApp\/ {\n        proxy_pass http:\/\/localhost:5080\/LiveApp\/;\n        proxy_http_version 1.1;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection \"upgrade\";\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    # Node.js \uc571 \ud504\ub85d\uc2dc \/ Node.js app proxy  (\/nodejs\/)\n    location \/nodejs\/ {\n        proxy_pass http:\/\/localhost:3000\/nodejs\/;  # &lt;=== \uc911\uc694: \/nodejs\/\ub85c \ud504\ub85d\uc2dc\n        proxy_http_version 1.1;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection \"upgrade\";\n        proxy_set_header Host $host;\n        proxy_cache_bypass $http_upgrade;\n    }\n\n    # \ub8e8\ud2b8 \uc815\uc801 \ud30c\uc77c \/ root static file\n    location \/ {\n        root \/var\/www\/html\/;\n        index index.html;\n        try_files $uri $uri\/ =404;\n    }\n}\n\n# HTTP \uc811\uadfc \uc2dc HTTPS\ub85c \ub9ac\ub514\ub809\uc158 \/ \rRedirect to HTTPS when accessing HTTP\nserver {\n    listen 80;\n    server_name host.domain.com;\n    return 301 https:\/\/$host$request_uri;\n}\n<\/code><\/pre>\n\n\n\n<p><strong>Nodejs test code<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const express = require('express');\nconst app = express();\nconst port = 3000;\n\n\/\/ \ub8e8\ud2b8 \uacbd\ub85c (\ud504\ub85d\uc2dc\ub97c \ud1b5\ud574 \uc9c1\uc811 \uc811\uadfc\ud558\ub294 \uacbd\uc6b0 \uc0ac\uc6a9 \uc548\ub428)\napp.get(\"\/\", (req, res) =&gt; {\n  res.send(\"Node.js \uc11c\ubc84 (\/)\ub97c \ud1b5\ud574 \uc811\uc18d\ud588\uc2b5\ub2c8\ub2e4.\");\n});\n\n\/\/ \ud504\ub85d\uc2dc\ub41c \uacbd\ub85c\napp.get(\"\/nodejs\/\", (req, res) =&gt; {\n  res.send(\"Node.js \uc11c\ubc84 (\/nodejs\/)\ub97c \ud1b5\ud574 \uc811\uc18d\ud588\uc2b5\ub2c8\ub2e4.\");\n});\n\napp.get(\"\/nodejs\/admin\", (req, res) =&gt; {\n  res.send(\"Node.js \uc11c\ubc84 (\/nodejs\/admin)\ub97c \ud1b5\ud574 \uc811\uc18d\ud588\uc2b5\ub2c8\ub2e4.\");\n});\n\napp.get(\"\/nodejs\/video\", (req, res) =&gt; {\n  res.send(\"Node.js \uc11c\ubc84 (\/nodejs\/video)\ub97c \ud1b5\ud574 \uc811\uc18d\ud588\uc2b5\ub2c8\ub2e4.\");\n});\n\napp.get(\"\/nodejs\/login\", (req, res) =&gt; {\n  res.send(\"Node.js \uc11c\ubc84 (\/nodejs\/login)\ub97c \ud1b5\ud574 \uc811\uc18d\ud588\uc2b5\ub2c8\ub2e4.\");\n});\n\n\/\/ \ud655\uc778\uc6a9\napp.get(\"\/liveapp\", (req, res) =&gt; {\n  res.send(\"Ant Media Server (\/liveapp)\uc73c\ub85c \uc9c1\uc811 \uc811\uc18d\ud588\uc2b5\ub2c8\ub2e4. (Nginx \ud504\ub85d\uc2dc \uc124\uc815 \ud655\uc778\uc6a9)\");\n});\n\napp.listen(port, () =&gt; {\n  console.log(`Node.js \uc11c\ubc84\uac00 http:\/\/localhost:${port} \uc5d0\uc11c \uc2e4\ud589 \uc911\uc785\ub2c8\ub2e4.`);\n});\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&#8212; \uc544\ub798\ub294 nginx\ub97c \uc6f9\uc11c\ubc84\ub85c \uc0ac\uc6a9\ud558\uace0 nodejs https \ud504\ub85d\uc2dc Andmedia server \uc758 https\ud504\ub85d\uc2dc\ud558\ub294 \uc124\uc815\uc785\ub2c8\ub2e4.Below is the configuration for using nginx as a web server and nodejs https proxy Andmedia server&#8217;s https proxy. https:\/\/host.domain.com\/nodejs\/ \u2192 Node.js \uc11c\ubc84 (\/nodejs\/)\ub97c \ud1b5\ud574 \uc811\uc18d\ud588\uc2b5\ub2c8\ub2e4. \/ You are accessing the Node.js server (\/nodejs\/). https:\/\/host.domain.com\/nodejs\/login \u2192 Node.js \uc11c\ubc84 (\/nodejs\/login)\ub97c \ud1b5\ud574 \uc811\uc18d\ud588\uc2b5\ub2c8\ub2e4. \/ You [&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,9,5,1],"tags":[],"class_list":["post-1389","post","type-post","status-publish","format-standard","hentry","category-linux","category-nodejs","category-reactnative","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=1389"}],"version-history":[{"count":27,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1389\/revisions"}],"predecessor-version":[{"id":1418,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/1389\/revisions\/1418"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=1389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=1389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=1389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}