2025-02-08 23:38:34 +01:00
2025-02-08 22:59:48 +01:00
2025-02-08 22:57:59 +01:00
2025-02-08 22:58:48 +01:00
2025-02-08 23:38:34 +01:00
2025-02-08 22:58:48 +01:00
2025-02-08 22:58:48 +01:00
2025-02-08 22:58:48 +01:00
2025-02-08 22:58:48 +01:00
2025-02-08 22:58:48 +01:00

HTTP Server

This is a simple HTTP server for linux operating system written in C. It supports basic HTTP requests, logging, etc.

Features

  • Handles GET requests for static files.
  • Supports a control menu for managing server status, logging, and configuration (currently basic).
  • Uses pthreads for concurrent client handling.
  • Includes basic logging functionality with timestamps.
  • Configuration is loaded from a JSON file (server.json).

Build Instructions

  1. Prerequisites:

    • GCC compiler
    • Make (recommended)
    • OpenSSL libraries (libssl, libcrypto)
    • pthreads library
    • cJSON library
  2. Clone the repository (optional):

    git clone https://github.com/Azreyo/Http-server  
    cd Http-server/
    
  3. Compile:

    gcc server.c config_parser.c server_config.c -o server -lssl -lcrypto -lpthread -pthread -lcjson -lcjson -I/usr/include/cjson
    

    Compile it in gcc

    make
    

    This command will use the provided Makefile to compile the source files, link the necessary libraries, and create the executable in the bin directory.

    make clean
    

    Cleanup of the unnecessary files after compiling

  4. Create www directory:

    mkdir www
    

    Place your HTML files (e.g., index.html) inside the www directory.

  5. Create server.json:

    Create a server.json file in the same directory as the executable with the following structure:

    {
      "port": 8080,
      "use_https": false,
      "log_file": "server.log",
      "max_threads": 4,
      "running": true
    }
    

    Adjust the values as needed. use_https is not yet implemented.

Run Instructions

  1. Get IP address of your device that the program will run on:
ip address
  1. Enable port 8080 for ufw
sudo ufw allow 8080 # 8080 is the default port
  1. Run it and enjoy
./bin/server  # Run the executable from the bin directory
Description
Http and https server made in C with high response time, secured connections and reliable server.
https://carbonc.eu Readme 411 KiB
Languages
C 79.7%
HTML 15.5%
Shell 2.1%
Makefile 1.7%
Dockerfile 1%