42Webserver / 42-Vienna-Webserv

This project is about writing our own HTTP server in C++
1 stars 0 forks source link

๐ŸŒ Webserv - An HTTP Server Project

Welcome to Webserv! This project was developed by a dedicated team of three developers: Nikolai, Florian, and Felix. Our goal was to create our own HTTP server to gain a deep understanding of how web servers function. Through this project, we explored various aspects of server development, enhanced our programming skills, and gained valuable experience in teamwork and project management.

๐Ÿ“š Key Learnings

During the development of Webserv, we acquired a range of skills and knowledge:

โš™๏ธ Configuration Keywords

Here is a brief description of the key configuration keywords used in our configuration file:

This configuration structure allows for flexible and powerful setup, enabling Webserv to handle various requests and serve content effectively.


๐Ÿ“ Example Configuration File: webserv.conf

Below is an example configuration file to help you launch your HTTP server. It is structured to handle various routes and methods, ensuring smooth operation.

http
{
    server
    {
        listen localhost:8080;  # The server will listen on localhost at port 8080
        root /your/path/app;    # Base directory for serving files

        location /
        {
            index index.html;    # Default file to serve for the root location
            allowed_methods GET; # Allowed methods for this location
        }

        location /delete
        {
            root /your/path/app/public/delete/;  # Directory for delete operations
            cgi_methods POST GET;                 # Allowed methods for CGI
            extension .py;                        # File extension for CGI scripts
            script_path /usr/bin/python3;        # Path to the Python interpreter
            error_page 404 /public/error/404.html; # Custom error page for 404 errors
        }

        location /contact
        {
            root /your/path/app/public/contact;  # Directory for contact page
            index contact.html;                  # Default file for contact location
        }

        location /game
        {
            root /your/path/app/public/game;     # Directory for game page
            index game.html;                     # Default file for game location
            allowed_methods GET;                 # Allowed methods for this location
        }

        location /overview
        {
            root /your/path/app/public/overview; # Directory for overview page
            index overview.html;                 # Default file for overview location
            cgi_methods POST GET;                # Allowed methods for CGI
            extension .py .sh;                   # File extensions for CGI scripts
            script_path /usr/bin/python3 /bin/bash; # Paths to interpreters for CGI
        }

        location /admin
        {
            root /your/path/app/public/admin;    # Directory for admin page
            allowed_methods GET POST;            # Allowed methods for this location
            cgi_methods POST GET;                # Allowed methods for CGI
            extension .py;                       # File extension for CGI scripts
            script_path /usr/bin/python3;       # Path to the Python interpreter
            index admin.py;                      # Default file for admin location
        }

        location /cgi-bin
        {
            root /your/path/app/public/cgi-bin/; # Directory for CGI scripts
            cgi_methods POST GET;                 # Allowed methods for CGI
            extension .py .sh;                    # File extensions for CGI scripts
            script_path /usr/bin/python3 /bin/bash; # Paths to interpreters for CGI
            upload /your/path/app/public/delete/remove/; # Directory for file uploads
            return 301 /;                        # Redirect to root on access
        }
    }
}

๐Ÿš€ How to Launch the Server

Follow these steps to get your server up and running:

  1. ๐Ÿ“ฅ Pull the GitHub Repository:

    git clone https://github.com/42Webserver/42-Vienna-Webserv.git
  2. ๐Ÿ“‚ Navigate to the Project Directory: Change into the directory of the cloned repository:

    cd 42-Vienna-Webserv
  3. โš™๏ธ Compile and Start the Server with Default Configuration: You can compile and start the server with the default configuration file in one step by running:

    make run
  4. ๐ŸŒ Access the Server: Open your web browser and navigate to http://localhost:8080 to access your application.

  5. ๐Ÿงช Test the Example Website: To demonstrate all the functions of our web server, sessions and cookies have been integrated into the example website. Log in under "Manage Files" and "Upload Files" using the following credentials:

    • Username: admin
    • Password: hello123
  6. ๐Ÿ› ๏ธ Test Different Routes: You can test various routes such as /delete, /contact, /game, /overview, and /admin to ensure everything is functioning as expected.

๐Ÿ“Œ Notes