[3] Nginx Server Setup - Connecting to C++ Web Framework



## 0. Researching C++ Web Frameworks

To achieve the goal of building a server in C++, I've started by researching suitable C++ web frameworks.
According to GPT recommendations, **Drogon** is popular, so I'll proceed with this framework first.

---

| Framework  | Advantages                                                                                 | Disadvantages                                                    |
|------------|-------------------------------------------------------------------------------------------|------------------------------------------------------------------|
| **Drogon** | Supports modern C++14/17 standards<br>Asynchronous programming and multi-thread support<br>Supports HTTP2 and WebSocket<br>High performance and user-friendly API<br>Active community and support | Initial setup can be complex due to many features             |
| **Pistache** | Lightweight design enables quick web server implementation<br>Suitable for RESTful API development<br>Simple code and easy to learn | Slow development and updates<br>Limited functionality       |
| **Crow**   | Intuitive usage similar to Python&#8217;s Flask<br>Includes JSON support and routing functionality<br>Lightweight design | Limited features, not ideal for complex applications<br>May lack active maintenance and support |
| **CppCMS** | Suitable for high-performance web application development<br>Provides features like session management and internationalization | Complex setup and steep learning curve<br>More difficult to use compared to other frameworks, with limited documentation |
| **Restbed** | Suitable for lightweight RESTful API development<br>Asynchronous and scalable design | Limited functionality, not ideal for large-scale projects<br>Lacks active updates and community support |


---



## 1. Installing Framework Dependencies

```
sudo yum install -y git cmake gcc-c++ libuuid-devel openssl-devel zlib-devel brotli-devel jsoncpp-devel libuuid libuuid-devel

```

If jsoncpp-devel is unavailable, install it separately.

---

### Separate installation of JSONCPP

```
# Download the JSONCPP source code  
git clone https://github.com/open-source-parsers/jsoncpp.git  
cd jsoncpp  

# Create build directory  
mkdir build  
cd build  

# Configure and build using CMake  
cmake .. -DCMAKE_BUILD_TYPE=Release  
make -j$(nproc)  

# Install  
sudo make install  

# Link installation path (specify the installed path, in this case, it is /usr/local/lib64)  
echo "/usr/local/lib64" | sudo tee /etc/ld.so.conf.d/jsoncpp.conf  
sudo ldconfig  

# Verification  
ldconfig -p | grep jsoncpp  

[root@vbox build] (master) $ ldconfig -p | grep jsoncpp  
        libjsoncpp.so.27 (libc6,x86-64) => /usr/local/lib64/libjsoncpp.so.27  
        libjsoncpp.so (libc6,x86-64) => /usr/local/lib64/libjsoncpp.so  
```

---

## 2. Building the Framework

```
git clone https://github.com/drogonframework/drogon.git
cd drogon

mkdir build
cd build 
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
sudo make install

```

---


### Error During Installation

```
CMake Error at CMakeLists.txt:137 (add_subdirectory):  
  The source directory  

    /root/drogon/trantor  

  does not contain a CMakeLists.txt file.
```

- Run the following command:  
git submodule update --init --recursive

- After running the command, go to the build directory and execute:  
```
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
sudo make install

Then rebuild.
```

---


### 3. Verifying the Framework

To check the version:  

```
[root@vbox drogon_ctl] (master) $ pwd
/root/drogon/build/drogon_ctl
[root@vbox drogon_ctl] (master) $ ./drogon_ctl version
     _
  __| |_ __ ___   __ _  ___  _ __
 / _` | '__/ _ \ / _` |/ _ \| '_ \
| (_| | | | (_) | (_| | (_) | | | |
 \__,_|_|  \___/ \__, |\___/|_| |_|
                 |___/

A utility for drogon
Version: 1.9.8
Git commit: 8541e671430f9605a62f1afbd786c1dbd54197d6
Compilation:
  Compiler: c++
  Compiler ID: GNU
  Compilation flags: -O3 -DNDEBUG -std=c++17 -I/usr/local/include
Libraries:
  postgresql: no  (pipeline mode: no)
  mariadb: no
  sqlite3: no
  ssl/tls backend: OpenSSL
  brotli: no
  hiredis: no
  c-ares: no
  yaml-cpp: no
  
```

### Run the Built Test Server in the Following Directory
/root/drogon/build/examples

```
[root@vbox examples] (master) $ ./helloworld  
20241103 16:23:09.594785 UTC 52417 INFO  Server running on 127.0.0.1:8848 - main.cc:95  
20241103 16:23:09.596557 UTC 52418 INFO  setBeforeListenSockOptCallback:10 - main.cc:76  
```

---

### Internal CURL Test
```
[root@vbox ~] $ curl -v 127.0.0.1:8848  
*   Trying 127.0.0.1:8848...  
* Connected to 127.0.0.1 (127.0.0.1) port 8848 (#0)  
> GET / HTTP/1.1  
> Host: 127.0.0.1:8848  
> User-Agent: curl/7.76.1  
> Accept: */*  
>  
* Mark bundle as not supporting multiuse  
< HTTP/1.1 200 OK  
< content-length: 13  
< content-type: text/html; charset=utf-8  
< server: drogon/1.9.8  
< date: Sun, 03 Nov 2024 16:22:09 GMT  
<  
* Connection #0 to host 127.0.0.1 left intact  
```
---


### Web Test
Reloading NGINX is necessary before running the web test.

```
worker_processes  10;

events {
    worker_connections  1024;
    use epoll;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;
    large_client_header_buffers 4 16k;

    server {
        listen       10099;
        server_name  localhost;

        location / {
            proxy_pass http://localhost:8848;  # Proxy to backend server
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}
```

After modifying the configuration, reload or restart NGINX:
./nginx -s reload" or


./nginx -s stop  
./nginx  


---

### Verifying Operation

<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDnd8B1aa2ngpsrxkCV6GnS3l_1PuJJsOYLAJi27B6KH8jFs93z9RfQ2ukUUADZmqgulYpD4U8EmLB4isOb5d8NCawmIrPa5kXKWOugXSio9opl9cuGIpsruyh4TNTbNiJ-_Es2RkvVqjAs9fv0gipSPKazUTVfyxYOwnNim0jA0ouf33vS_fP0zXR/s360/nginx-3.PNG" style="display: block; padding: 1em 0; text-align: center; "><img alt="nginx" border="0" data-original-height="180" data-original-width="360" loading="lazy" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDnd8B1aa2ngpsrxkCV6GnS3l_1PuJJsOYLAJi27B6KH8jFs93z9RfQ2ukUUADZmqgulYpD4U8EmLB4isOb5d8NCawmIrPa5kXKWOugXSio9opl9cuGIpsruyh4TNTbNiJ-_Es2RkvVqjAs9fv0gipSPKazUTVfyxYOwnNim0jA0ouf33vS_fP0zXR/s320-rw/nginx-3.PNG" width="320"/></a></div>

Web(10099) -> VM -> NGINX (10099) -> Drogon (8848)
This setup confirms the server operates in the above structure.




<!-- 목록을 표시할 HTML 컨테이너 -->
<div>
    <h3>Related Links</h3>
    <ul id="label-post-list">
        <!-- 여기에 게시물 목록이 추가됩니다 -->
    </ul>
</div>

---

<!-- 목록을 표시할 HTML 컨테이너 -->
<div>
    <h3>Recommended Link</h3>
    <ul id="label-post-list-include">
        <!-- 여기에 게시물 목록이 추가됩니다 -->
    </ul>
</div>

---



댓글

이 블로그의 인기 게시물

윤석열 계엄령 선포! 방산주 대폭발? 관련주 투자 전략 완벽 분석

대통령 퇴진운동 관련주: 방송·통신·촛불수혜주 완벽 분석

키움 OPEN API MFC 개발 (1)