{"id":5308,"date":"2026-04-13T16:58:00","date_gmt":"2026-04-13T07:58:00","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=5308"},"modified":"2026-04-13T17:07:46","modified_gmt":"2026-04-13T08:07:46","slug":"webserver-httplib-reverse-proxy","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/04\/13\/webserver-httplib-reverse-proxy\/","title":{"rendered":"[Webserver]httplib webserver+reverse proxy(macoOS,Linux)"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \ub9ac\ubc84\uc2a4 \ud504\ub85d\uc2dc\ub294 \uc6f9\uc11c\ubc84\uc5d0 \ub4e4\uc5b4\uc628 \uc694\uccad\uc744 \ub2e4\ub978 \uc11c\ubc84\ub85c \uc694\uccad\uc744 \uc804\ub2ec\ud558\uae30 \uc704\ud574\uc11c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.<br>A reverse proxy is used to forward requests received by a web server to another server.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ub9ac\ubc84\uc2a4 \ud504\ub85d\uc2dc\uac00 \uc14b\ud305\ub41c \uc11c\ubc84http,https,5080)\uc640  \uc2e4\uc81c\ub85c \uc2e4\ud589\ub420 \uc11c\ubc84(http,3000)\ub97c \uc2e4\ud589\ud569\ub2c8\ub2e4.<br>Run the server with the reverse proxy set up (http,https,5080) and the server to be actually executed (http,3000).<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c \ub2e4\uc74c\ucc98\ub7fc 5080\ud3ec\ud2b8\ub85c \uc2e4\ud589\ud558\uba74 \ud3ec\ud2b83000\ubc88\uc778 \uc11c\ubc84\uc815\ubcf4\ub97c \ubcfc \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>If you run it on port 5080 in a browser as follows, you can view the server information on port 3000.<\/p>\n\n\n\n<p>\u2714\ufe0fLinux : https:\/\/host.domain.org:5080\/api<\/p>\n\n\n\n<p>\u2714\ufe0fmacOS : http:\/\/localhost:5080\/api<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb macOS\uc5d0\uc11c\ub294 http\uc11c\ubc84\ub97c \ud14c\uc2a4\ud2b8\ud558\uace0 Linux\uc11c\ubc84\uc5d0\uc11c\ub294 https\uc11c\ubc84\ub97c \ud14c\uc2a4\ud2b8\ud569\ub2c8\ub2e4.<br>Test the HTTP server on macOS and the HTTPS server on Linux.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ubc29\ud654\ubcbd\uc5d0\uc11c 3000\ubc88 \ud3ec\ud2b8\ub97c \ucd94\uac00\ub85c \uc624\ud508 \ud569\ub2c8\ub2e4.(iptables)<br>Open port 3000 additionally in the firewall (iptables).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo iptables -I INPUT -p tcp --dport 3000 -j ACCEPT\n$ sudo netfilter-persistent save<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ub098\uba38\uc9c0 \ubc29\ud654\ubcbd \uc124\uc815 \ubd80\ubd84 \uc124\uba85\uc740 \uc774\uc804 \uac8c\uc2dc\ubb3c\uc744 \ucc38\uc870\ud558\uc138\uc694<br>Please refer to the previous post for the explanation of the remaining firewall settings.<\/p>\n\n\n\n<p>\u2714\ufe0f httplib.h(0.42.0)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -L https:\/\/raw.githubusercontent.com\/yhirose\/cpp-httplib\/master\/httplib.h -o httplib.h<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83d\udc49\ud83c\udffbHttp server(http_server.cpp)-Reverse proxy setting<\/p>\n\n\n\n<p>\u2714\ufe0f \ucf54\ub4dc \/ Code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"httplib.h\"\n#include &lt;iostream&gt;\n\nstatic void copy_response(const httplib::Result&amp; r, httplib::Response&amp; res) {\n    if (!r) {\n        res.status = 502;\n        res.set_content(\"Backend server is unreachable.\", \"text\/plain; charset=utf-8\");\n        return;\n    }\n    res.status = r-&gt;status;\n\n    for (const auto&amp; h : r-&gt;headers) {\n        if (h.first == \"Connection\" || h.first == \"Keep-Alive\" ||\n            h.first == \"Proxy-Authenticate\" || h.first == \"Proxy-Authorization\" ||\n            h.first == \"TE\" || h.first == \"Trailers\" ||\n            h.first == \"Transfer-Encoding\" || h.first == \"Upgrade\") {\n            continue;\n        }\n        res.set_header(h.first.c_str(), h.second.c_str());\n    }\n\n    res.body = r-&gt;body;\n}\n\nint main() {\n    httplib::Server svr;\n\n    \/\/ \/api \uc640 \/api\/... \ubaa8\ub450 \ucc98\ub9ac\n    svr.Get(R\"(\/api.*)\", &#91;](const httplib::Request&amp; req, httplib::Response&amp; res) {\n        std::cout &lt;&lt; \"Proxying: \" &lt;&lt; req.method &lt;&lt; \" \" &lt;&lt; req.path &lt;&lt; \"\\n\";\n\n        httplib::Client cli(\"localhost\", 3000);\n\n        if (auto backend_res = cli.Get(req.path.c_str())) {\n            copy_response(backend_res, res);\n        } else {\n            res.status = 502;\n            res.set_content(\"Backend server is unreachable.\", \"text\/plain; charset=utf-8\");\n        }\n    });\n\n    std::cout &lt;&lt; \"Proxy server listening on http:\/\/0.0.0.0:5080\\n\";\n    svr.listen(\"0.0.0.0\", 5080);\n\n    return 0;\n}\n<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ucef4\ud30c\uc77c \/ Compiling<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>g++ -o http_server http_server.cpp -std=c++17 -pthread <\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc2e4\ud589 \/ Run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/http_server<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffbHttps server(https_server.cpp)-Reverse proxy setting<\/p>\n\n\n\n<p>\u2714\ufe0f \uc778\uc99d\uc11c \ubcf5\uc0ac \/ Copy certificate<\/p>\n\n\n\n<p>&#8212; \uc774\uc804\uc5d0 \ubc1c\uae09\ubc1b\uc740 Let&#8217;s Encrypt\uc778\uc99d\uc11c\uc785\ub2c8\ub2e4.(\uc774\uc804 \uac8c\uc2dc\ubb3c \ucc38\uc870)<br>Please refer to the previous post for the explanation of the remaining firewall settings.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo cp \/etc\/letsencrypt\/live\/host.domain.org\/fullchain.pem .\/\n$ sudo cp \/etc\/letsencrypt\/live\/host.domain.org\/privkey.pem .\/\n\n# \ub0b4 \uacc4\uc815\uc73c\ub85c \uc18c\uc720\uad8c \ubcc0\uacbd \/ Change ownership to my account\n$ sudo chown username:username *.pem  <\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ucf54\ub4dc \/ Code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#define CPPHTTPLIB_OPENSSL_SUPPORT\n#include \"httplib.h\"\n#include &lt;iostream&gt;\n\nstatic void copy_response(const httplib::Result&amp; r, httplib::Response&amp; res) {\n    if (!r) {\n        res.status = 502;\n        res.set_content(\"Backend server is unreachable.\", \"text\/plain; charset=utf-8\");\n        return;\n    }\n    res.status = r-&gt;status;\n\n\n    for (const auto&amp; h : r-&gt;headers) {\n        if (h.first == \"Connection\" || h.first == \"Keep-Alive\" ||\n            h.first == \"Proxy-Authenticate\" || h.first == \"Proxy-Authorization\" ||\n            h.first == \"TE\" || h.first == \"Trailers\" ||\n            h.first == \"Transfer-Encoding\" || h.first == \"Upgrade\") {\n            continue;\n        }\n        res.set_header(h.first.c_str(), h.second.c_str());\n    }\n\n    res.body = r-&gt;body;\n}\n\nint main() {\n    httplib::SSLServer svr(\".\/fullchain.pem\", \".\/privkey.pem\");\n\n    if (!svr.is_valid()) {\n        std::cerr &lt;&lt; \"SSL server setup failed\\n\";\n        return 1;\n    }\n\n    \/\/ \ubaa8\ub4e0 \/api\/... \uc694\uccad\uc744 \ud504\ub85d\uc2dc \ucc98\ub9ac\n    svr.Get(R\"(\/api.*)\", &#91;](const httplib::Request&amp; req, httplib::Response&amp; res) {\n        httplib::Client cli(\"localhost\", 3000);\n\n        if (auto backend_res = cli.Get(req.path.c_str())) {\n            copy_response(backend_res, res);\n        } else {\n            res.status = 502;\n            res.set_content(\"Backend server is unreachable.\", \"text\/plain; charset=utf-8\");\n        }\n    });\n\n    std::cout &lt;&lt; \"Proxy server listening on https:\/\/0.0.0.0:5080\\n\";\n    svr.listen(\"0.0.0.0\", 5080);\n\n    return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ucef4\ud30c\uc77c \/ Compiling<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>g++ -o https_server https_server.cpp -std=c++17 -pthread -lssl -lcrypto<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc2e4\ud589 \/ Run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/https_server<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb http server(httplib_server.cpp)<\/p>\n\n\n\n<p>\u2714\ufe0f \ucf54\ub4dc \/ Code<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"httplib.h\"\n#include &lt;iostream&gt;\n\nint main()\n{\n  httplib::Server svr;\n\n  svr.Get(\"\/\",&#91;](const httplib::Request &amp;req, httplib::Response &amp;res){\n      res.set_content(\"&lt;h1&gt;Hi! silver hand!!!\ud83d\udc4b&lt;\/h1&gt;\", \"text\/html; charset=utf-8\");\n  });\n\n  svr.Get(\"\/api\",&#91;](const httplib::Request &amp;req, httplib::Response &amp;res){\n   \/\/res.set_content(\"Hello Red Dead Redemption!\",\"text\/plain\");\n   res.set_content(\"&lt;h1&gt;\ud83d\udc49\ud83c\udffbHello Red Dead Redemption-reverse proxy ok!!&lt;\/h1&gt;\", \"text\/html; charset=utf-8\");\n  });\n\n  std::cout &lt;&lt; \"cpp-httplib server listening on http:\/\/localhost:3000\" &lt;&lt; std::endl;\n  svr.listen(\"0.0.0.0\", 3000);\n\n  return 0;\n}<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ucef4\ud30c\uc77c \/ Compiling<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>g++ -o https_server https_server.cpp -std=c++17<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc2e4\ud589 \/ Run<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/httplib_server<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc11c\ubc84 \uc2e4\ud589 \ubc29\ubc95 \/ How to run the server<\/p>\n\n\n\n<p>\u2714\ufe0f \uc704\uc5d0\uc11c \uc791\uc131\ub41c \ucf54\ub4dc\ub97c \uc544\ub798\ucc98\ub7fc \ud14c\uc2a4\ud2b8 \ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<br>You can test the code written above as follows.<\/p>\n\n\n\n<p>\u2714\ufe0f macOS<\/p>\n\n\n\n<p>&#8212; 5080\uc11c\ubc84\uc640 3000\ubc88 \uc11c\ubc84\ub97c \uc2e4\ud589\ud569\ub2c8\ub2e4.<br>Run server 5080 and server 3000.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"263\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-terminal-jpg-1024x263.jpg\" alt=\"\" class=\"wp-image-5311\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-terminal-jpg-1024x263.jpg 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-terminal-jpg-300x77.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-terminal-jpg-768x198.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-terminal-jpg-400x103.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-terminal-jpg-800x206.jpg 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-terminal-jpg.jpg 1166w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\ub85c\uceec \ud130\ubbf8\ub110 \/ local terminal<\/figcaption><\/figure>\n\n\n\n<p>&#8212; \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c 5080\ud3ec\ud2b8\uc11c\ubc84\ub85c \uc811\uc18d\ud569\ub2c8\ub2e4. \/ Connect to the server on port 5080 in your browser.<br>(http:\/\/localhost:5080\/api)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"236\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-br-jpg-1024x236.jpg\" alt=\"\" class=\"wp-image-5313\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-br-jpg-1024x236.jpg 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-br-jpg-300x69.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-br-jpg-768x177.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-br-jpg-400x92.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-br-jpg-800x185.jpg 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/local-br-jpg.jpg 1464w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\ub85c\uceec\ube0c\ub77c\uc6b0\uc800 \/ local browser<\/figcaption><\/figure>\n\n\n\n<p>\u2714\ufe0f Linux<\/p>\n\n\n\n<p>&#8212; 5080\uc11c\ubc84\uc640 3000\ubc88 \uc11c\ubc84\ub97c \uc2e4\ud589\ud569\ub2c8\ub2e4.<br>Run server 5080 and server 3000.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"211\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-console-jpg-1024x211.jpg\" alt=\"\" class=\"wp-image-5316\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-console-jpg-1024x211.jpg 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-console-jpg-300x62.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-console-jpg-768x158.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-console-jpg-400x82.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-console-jpg-800x165.jpg 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-console-jpg.jpg 1186w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\ub9ac\ub205\uc2a4\uc11c\ubc84 \ud130\ubbf8\ub110  \/ Linux Server Terminal<\/figcaption><\/figure>\n\n\n\n<p>&#8212; \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c 5080\ud3ec\ud2b8\uc11c\ubc84\ub85c \uc811\uc18d\ud569\ub2c8\ub2e4. \/ Connect to the server on port 5080 in your browser.<br>(https:\/\/host.domain.org:5080\/api)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"235\" src=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-br-jpg-1024x235.jpg\" alt=\"\" class=\"wp-image-5319\" srcset=\"https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-br-jpg-1024x235.jpg 1024w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-br-jpg-300x69.jpg 300w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-br-jpg-768x176.jpg 768w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-br-jpg-400x92.jpg 400w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-br-jpg-800x184.jpg 800w, https:\/\/www.freelifemakers.org\/wordpress\/wp-content\/uploads\/2026\/04\/cloud-br-jpg.jpg 1490w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">\ub9ac\ub205\uc2a4 \uc11c\ubc84 \ud130\ubbf8\ub110 \/ Linux Server Terminal<\/figcaption><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \ub9ac\ubc84\uc2a4 \ud504\ub85d\uc2dc\ub294 \uc6f9\uc11c\ubc84\uc5d0 \ub4e4\uc5b4\uc628 \uc694\uccad\uc744 \ub2e4\ub978 \uc11c\ubc84\ub85c \uc694\uccad\uc744 \uc804\ub2ec\ud558\uae30 \uc704\ud574\uc11c \uc0ac\uc6a9\ud569\ub2c8\ub2e4.A reverse proxy is used to forward requests received by a web server to another server. \ud83d\udc49\ud83c\udffb \ub9ac\ubc84\uc2a4 \ud504\ub85d\uc2dc\uac00 \uc14b\ud305\ub41c \uc11c\ubc84http,https,5080)\uc640 \uc2e4\uc81c\ub85c \uc2e4\ud589\ub420 \uc11c\ubc84(http,3000)\ub97c \uc2e4\ud589\ud569\ub2c8\ub2e4.Run the server with the reverse proxy set up (http,https,5080) and the server to be actually executed (http,3000). \ud83d\udc49\ud83c\udffb \ube0c\ub77c\uc6b0\uc800\uc5d0\uc11c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,1],"tags":[],"class_list":["post-5308","post","type-post","status-publish","format-standard","hentry","category-cpp","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5308","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=5308"}],"version-history":[{"count":11,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5308\/revisions"}],"predecessor-version":[{"id":5323,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5308\/revisions\/5323"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=5308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=5308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=5308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}