Giter Site home page Giter Site logo

wangalpha / mywebserver Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chenanga/mywebserver

0.0 1.0 0.0 33.96 MB

Linux下C++轻量级Web服务器

Home Page: http://web.blogca.cn/

Shell 0.18% C++ 94.67% C 1.35% Makefile 0.23% HTML 3.00% CMake 0.56%

mywebserver's Introduction

chenWeb

项目描述

Linux下C++轻量级Web服务器,基于非阻塞I/O和模拟Proactor事件处理模式的高并发服务器,支持解析GET、POST请求,能够响应静态资源的请求。

  • 使用线程池、非阻塞Socket、Epoll (LT模式)和模拟Proactor实现的并发模型;
  • 使用状态机解析HTTP请求报文,支持GET和POST请求;
  • 基于升序的双向链表实现的超时长连接清除,异步的日志系统;
  • 访问服务器数据库实现Web端用户注册、登录功能,可以请求服务器图片和视频文件;
  • 支持YAML文件配置。

在线访问

演示网站的地址:http://web.blogca.cn/

演示

目录

安装和使用

准备工作

  • 服务器测试环境

    • Ubuntu版本18.04
    • MySQL版本5.7.38
  • 浏览器测试环境

    • Windows、Linux均可
    • Chrome
    • FireFox
    • edge
  • 测试前确认已安装MySQL数据库

# 建立 webserver 库
create database webserver;

# 创建user表
USE webserver;
CREATE TABLE user(
    username char(50) nullptr,
    password char(50) nullptr
)ENGINE=InnoDB;

# 添加数据
INSERT INTO user(username, password) VALUES('chen', '12345678');
  • 修改config.yaml中的数据库初始化信息
# 数据库登录名,密码,库名
# 数据库相关参数
databaseParameter:

  # 登录用户名
  user: "chen"

  # 登录密码
  passwd: "12345678"

  # 数据库名称
  databasename: "webserver"

服务器端代码编译构建 (以下方式选其一即可)

方式1: CMake编译构建 (推荐)

环境:

  • cmake >= 3.20
  • gcc
  • g++
  1. 构建编译
cd 当前目录
sh ./build.sh
  1. 运行
./bin/chenWeb

方式2:makefile编译构建

环境:

  • cmake >= 3.20
  • gcc
  • g++
  1. 需要先配置yaml-cpp
// yaml-cpp 配置
git clone https://github.com/jbeder/yaml-cpp.git
cd yaml-cpp/
mkdir build && cd build
cmake .. && make -j
sudo make install
  1. 构建编译本项目
// chenWeb 配置
cd 当前目录
make
  1. 运行
./chenWeb

浏览器端运行

ip:10000/

项目结构

chenWeb/

|-- config/                              # yaml配置文件解析相关
|-- http/                                # http连接处理解析
|-- lock_/                                # 互斥锁
|-- log/                                 # 日志
|-- pool/                                # 线程池
|-- utils/                            	 # 工具类
|-- include/                             # 依赖的第三方库的头文件
|   |--yaml-cpp/                         # yaml配置文件解析
|-- lib/                                 # 依赖的第三方库
|   |--yaml-cpp/                         # yaml配置文件解析
|-- config.yaml                          # 配置文件
|-- main.cpp                             # 入口函数
|-- CMakeLists.txt
|-- makefile     
|-- build.sh
|-- README.md

测试

TODO

1、http解析使用正则表达式

2、上传/下载文件

3、解析更多的http头部字段

4、加入cookie或者session验证

5、密码MD5加密

6、注册时候加入验证码

引用

  1. Github jbeder/yaml-cpp

mywebserver's People

Contributors

chenanga avatar wangalpha avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.