FastCGI 文件上传功能实例
2022-12-03 06:56
浏览:230次
简介
书接上文:[在 1024Code 上通过Nginx配置C++的CGI程序实例](),我们了解了如何安装和配置 Nginx Web 服务器,并成功跑起了CGI 的 demo 程序。 这里,我们在其基础上,使用 FastCGI 来实现一个文件上传功能实例(实例来源于 [菜鸟教程:简单的 URL 实例:Get 方法](https://www.runoob.com/cplusplus/cpp-web-programming.html) ): 1、首先需要下载 cgicc 库,实现这个实例需要用到这个库 ``` $ wget https://ftp.gnu.org/gnu/cgicc/cgicc-3.2.19.tar.gz $ tar xzf cgicc-3.2.19.tar.gz ``` 2、编译和安装 cgicc ``` $ cd cgicc-X.X.X/ $ ./configure --prefix=/usr $ make ``` 因为代码空间容器环境的用户为 runner(非 root 用户),我们没有写入 /usr/lib 目录的权限,所以 make install 时,我们需要指定安装这个库到其他路径: ``` $ make install DESTDIR=/home/runner/app ``` 3、配置 linux 动态库环境变量( [LD_LIBRARY_PATH](https://baike.baidu.com/item/LD_LIBRARY_PATH/9391538?fr=aladdin) )指定查找共享库(动态链接库)时除了默认路径之外的其他路径。 ``` { pkgs ? import <nixpkgs> {} }: pkgs.mkShell { shellHook = '' alias ll="ls -l" export LD_LIBRARY_PATH=/home/runner/app/usr/lib ... ``` 修改 .1024nix 文件,在文件中添加 export LD_LIBRARY_PATH=/home/runner/app/usr/lib,并执行 nix-shell .1024nix 完成动态库环境变量配置。 4、创建 cpp_uploadfile.cpp 文件,并实现程序方法 5、编译 cpp_uploadfile.cpp ``` g++ -o /home/runner/app/nginx/html/cpp_uploadfile.cgi cpp_uploadfile.cpp -L/home/runner/app/usr/lib -I/home/runner/app/usr/include -lcgicc ``` 其中: - -L 将所要链接的库文件所在的路径告诉gcc - -I 指定第三方库头文件的位置 - -l 指定需要链接的库 6、将编译命令配置到运行按钮,点击运行按钮运行,测试实例程序结果 ![运行并测试实例结果](https://1024-staging-1258723534.cos.ap-guangzhou.myqcloud.com/doc_assets/Cases/runfastcgiuploadfile.gif)
一起来交流一下吧~
评论加载中...
Copyright © 2022-2024 1024Code 粤ICP备19030132号-9