https://github.com/johnguoy/simple_httpd
一个简单的 HTTP 服务器。
https://github.com/johnguoy/simple_httpd
c89 http httpd linux webserver
Last synced: 4 months ago
JSON representation
一个简单的 HTTP 服务器。
- Host: GitHub
- URL: https://github.com/johnguoy/simple_httpd
- Owner: JohnGuoy
- License: apache-2.0
- Created: 2021-06-28T15:41:32.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-04T15:14:00.000Z (about 4 years ago)
- Last Synced: 2025-03-14T02:11:16.155Z (11 months ago)
- Topics: c89, http, httpd, linux, webserver
- Language: C
- Homepage:
- Size: 23.4 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 一个简单的 HTTP 服务器
使用 C 语言(C89)编写,基于 Linux 多线程的一个简单的 HTTP 服务器,支持 Python 或者 PHP 动态脚本。
## 构建
软件构建环境需求:
* Linux 操作系统
* gcc 编译器
* cmake 构建器
如果要测试 Python 或者 PHP 动态脚本,那么还需要安装并配置好 Python 或者 PHP 的运行环境。
克隆代码到本地工作目录:
`$ git clone https://github.com/JohnGuoy/simple_httpd.git`
构建:
```bash
$ cd ./simple_httpd/build/
$ cmake ..
-- The C compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /root/Projects/TCP-IP/24.2/build
$ make
Scanning dependencies of target simple_httpd
[100%] Building C object CMakeFiles/simple_httpd.dir/main.c.o
Linking C executable simple_httpd
[100%] Built target simple_httpd
```
得到可执行程序 simple_httpd。
## 运行
运行 simple_httpd 程序,绑定任意未被占用的端口,Web 根目录默认是当前工作目录:
`$ ./simple_httpd 6677`
打开浏览器,输入以下 URL 进行测试:
```url
http://< 运行 simple_httpd 程序的服务器的 IP>:6677/index.html
http://< 运行 simple_httpd 程序的服务器的 IP>:6677/index.py
http://< 运行 simple_httpd 程序的服务器的 IP>:6677/index.php
http://< 运行 simple_httpd 程序的服务器的 IP>:6677/index1.html
```