Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/m0saan/webserv
this is a simple implementation of the HTTP server
https://github.com/m0saan/webserv
cgi client-server cpp cpp98 http-server request-response socket-programming
Last synced: about 1 month ago
JSON representation
this is a simple implementation of the HTTP server
- Host: GitHub
- URL: https://github.com/m0saan/webserv
- Owner: m0saan
- Created: 2021-10-23T08:00:37.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-12-22T13:46:13.000Z (almost 3 years ago)
- Last Synced: 2024-10-13T16:41:09.922Z (2 months ago)
- Topics: cgi, client-server, cpp, cpp98, http-server, request-response, socket-programming
- Language: C++
- Homepage:
- Size: 20.2 MB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# webserv
#### Serer Block Configurations
- A virtual server is defined by a server directive.
- A server block is a subset of servers’s configuration that defines a virtual server used to handle requests of a defined type.
-
```
server {
# Server configuration
}
```
- It is possible to add multiple server directives into the http context to define multiple virtual servers.
```
server {
# Server configuration
}
server {
# Other Server configuration
}
```
- The server configuration block usually includes a listen directive to specify the IP address and port on which the server listens for requests.
```
server {
# Server configuration
listen 127.0.0.1:8080
# Or
host 127.0.0.1
port 8080
}
```
- If a port is omitted, the standard port is used. Likewise, if an address is omitted, the server listens on all addresses.
- If the listen directive is not included at all, the “standard” port is 80/tcp and the “default” port is 8000/tcp, depending on superuser privileges.
- If there are several servers that match the IP address and port of the request, the server tests the request’s Host header field against the server_name directives in the server blocks.
- If the Host header field does not match a server name, should routes the request to the default server for the port on which the request arrived. The default server is the first one listed in the config file, unless you include the default_server parameter to the listen directive to explicitly designate a server as the default.### Serving Static Content
An important web server task is serving out files (such as images or static HTML pages). You will implement an example where, depending on the request, files will be served from different local directories: /data/www (which may contain HTML files) and /data/images (containing images). This will require editing of the configuration file and setting up of a server block inside the http block with two location blocks.First, create the /data/www directory and put an index.html file with any text content into it and create the /data/images directory and place some images in it.
Next, open the configuration file. The default configuration file already includes several examples of the server block, mostly commented out. For now comment out all such blocks and start a new server block:
```
http {
server {
}
}
```
Generally, the configuration file may include several server blocks distinguished by ports on which they listen to and by server names. Once nginx decides which server processes a request, it tests the URI specified in the request’s header against the parameters of the location directives defined inside the server block.Add the following location block to the server block:
```
location / {
root /data/www;
}
```
This location block specifies the “/” prefix compared with the URI from the request. For matching requests, the URI will be added to the path specified in the root directive, that is, to /data/www, to form the path to the requested file on the local file system. If there are several matching location blocks nginx selects the one with the longest prefix. The location block above provides the shortest prefix, of length one, and so only if all other location blocks fail to provide a match, this block will be used.Next, add the second location block:
```
location /images/ {
root /data;
}
```
It will be a match for requests starting with /images/ (location / also matches such requests, but has shorter prefix).The resulting configuration of the server block should look like this:
```
server {
location / {
root /data/www;
}location /images/ {
root /data;
}
}
```This is already a working configuration of a server that listens on the standard port 80 and is accessible on the local machine at http://localhost/. In response to requests with URIs starting with /images/, the server will send files from the /data/images directory. For example, in response to the http://localhost/images/example.png request nginx will send the /data/images/example.png file. If such file does not exist, nginx will send a response indicating the 404 error. Requests with URIs not starting with /images/ will be mapped onto the /data/www directory. For example, in response to the http://localhost/some/example.html request nginx will send the /data/www/some/example.html file.
### - Observations :
[![forthebadge](https://forthebadge.com/images/badges/made-with-c-plus-plus.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)### Made BY :
[moboustt](https://github.com/M0-san)
[mbani](https://github.com/mbani01)
[mamoussa](https://github.com/mamoussa405)