You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
5.2 KiB

2 years ago
## Localhost
2 years ago
HTTP, HyperText Transfer Protocol, standard application-level protocol used for exchanging files on the World Wide Web.Each Web browsers are HTTP clients that send file requests to Web servers, which in turn handle the requests via an HTTP service.
### Instructions
#### Server
2 years ago
The project can be written in one of these languages [Rust,Go,C++,C...]
- Your server must not crash for any reason.
2 years ago
- Any request to your server should never runing forever.
- Your server can listen on multiple servers and ports at the same time without any conflict.
- You must use only one process and no threads.
- You must use `exec` functions only in `CGI` part.
- Your server must be compatible with the last version of your chosen browser .
- You can use `NGINX` to compare headers and answer behaviors with your server.
- You must manage at least [`GET`, `POST`, `DELETE`] methods.
2 years ago
- You must handle customization errors *(Binding error,wrong configue file...)*.
- You must create error page for at least for the following error codes [400,311,403,404,405,413].
- You must execute `CGI` based on certain file extensions such as [`.php`,`.py`,...] at least one.
2 years ago
- The `CGI` should run in the correct directory for relative path file access.
2 years ago
- You must use the enverement paramatre of `CGI`.
- Your server must receive a request from the browser and send a response using the HTTP header and body.
- Your server must call `select` function (or equivalent function) one time only.
- You must manage chunked and unchunked requests.
- You must set the right status for each response.
2 years ago
here is an example of an HTTP request with `GET` method:
```http
GET /Welcome.html HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Host: www.01talent.com
Accept-Language: en-us
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
```
and here is an example of an HTTP response :
```http
HTTP/1.1 404 Not Found
Date: Thu, 19 Jul 2022 10:36:20 GMT
Server: Hserver/1.1.0
```
2 years ago
> Stress tests your server. It must stay available at all cost. use this command to test it `siege -b [IP]:[PORT]`
the availability should be up to 95.99
2 years ago
> Learn about [CGI](https://en.wikipedia.org/wiki/Common_Gateway_Interface)
#### Configurations File
2 years ago
This an example of a simple server configuration :
```
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
error_page Mozilla 404 /usr/share/nginx/errors/404.html;
client_body_size 10m;
location /
{
http_methods GET POST DELETE;
index index.html
2 years ago
upload_status on;
upload_path /usr/share/nginx/upload; //depends on "upload_status"
}
}
```
2 years ago
In the example above if the "upload_status" is "off", there is no need for "upload_path."
You have to base your server on this example bbut you must test also more complex configurations with multiple locations and ports and multiple servers such as:
```
{
server {
listen 80;
server_address 127.0.0.1;
server_name localhost;
...
...
...
location ...{
}
location ...{
}
}
server {
listen 5000;
listen 5001;
server_address 192.182.2.1;
server_name 01edu.com;
...
...
...
location ...{
}
}
server {
listen 5001;
listen 5002;
listen 5003;
server_address 192.186.2.54;
2 years ago
server_name 01talent.com;
...
...
...
location ...{
}
location ...{
}
location ...{
}
}
}
```
2 years ago
The Main Rules :
- Choose the host(server_address) and a port or multiple ports for each server.
- The first server for a host:port will be the default if the "server_name" didn't mutch any other servers "server_name".
- Setup default error pages.
2 years ago
- Limit client body size for uploads.
- Setup routes with one or multiple of the following rules/configuration (routes won't be using regexp):
- Define a list of accepted HTTP methods for the route.
- Define an HTTP redirection.
2 years ago
- Define a directory or a file from where the file should be searched (for example, if URL /test is rooted to /usr/Desktop, url /usr/Desktop/tmp/folder1/folder2).
- Turn on or off the directory listing.
- Set a default file to answer if the request is a directory.
2 years ago
- No need to manage comments "(#)".
to check the syntax of the config file you must run this :
```console
$ ./localhost -t GoodConfigFile.conf
Localhost : the configuration file GoodConfigFile.conf syntax is ok
$ ./localhost -t WrongConfigFile.conf
2 years ago
you miss server_addr in server 3
```
2 years ago
If your config file syntax is right :
2 years ago
2 years ago
```console
$ ./localhost Myconfigfile.conf
Listening on [IP]:[PORT]
Listening on [IP]:[PORT2]
```
> If you’ve got a question about one behavior, you should compare your program behavior with NGINX’s.
### Bonus
- Add multiple `CGI`
- Create a php page and connect it with a mysql database.
- The "PHP" page should named `mysql.php` and should be in the root path.