To get start working with YOPS, perform following steps. And remember that these instructions refer to the latest release. There may be some differences in older releases.
STEP 1. Downloading and unpacking
Download YOPS tarball,
place downloaded file into your home directory and unpack the archive:
bzip2 -d yops-yyyy-mm-dd.tar.bz2 tar xf yops-yyyy-mm-dd.tar
After unpacking, 2 directories should appear in your home, swebs and www. First one contains server sources, and the second this documentation (in docs subdir), configuration file (.conf/config) and empty log file (.log/access.log)
STEP 2. Compiling the server
Before compiling make sure you have libcurl4-openssl-dev package installed on your system.
YOPS uses this library for handling URL encoded strings, because i was
too lazy to implement that myself :)
Goto swebs directory and type make:
you@host:~$ cd swebs you@host:~/swebs$ you@host:~/swebs$ make
If you see make output just as shown below then everything is allright and you can proceed to next step, and if not - something went wrong :( In the latter case feel free to contact me
gcc -O3 -Wall -c -o swebs.o swebs.c swebs.c: In function ‘swebs_gen_jobid’: swebs.c:886: warning: cast from pointer to integer of different size swebs.c:887: warning: cast from pointer to integer of different size gcc -O3 -Wall -c -o soket.o soket.c gcc -O3 -Wall -c -o utils.o utils.c gcc -O3 -Wall -c -o http.o http.c gcc -O3 -Wall -c -o main.o main.c gcc -o swebs \ swebs.o \ soket.o \ utils.o \ http.o \ main.o \ -lpthread -lcurl -lcrypt gcc -Os -Wall -c -o cong.o cong.c gcc -o cong cong.o soket.o http.o swebs.o utils.o -lcurl -lcrypt
STEP 3. Optionally, configuring the server
For now, just skip this step. You can do it later if you want,
see below.
STEP 4. Running the server
Type ./swebs to run the server and make sure it's working.
In the address line of your favorite browser type
http://localhost:8080/docs/using.html
You should see same text you are reading just now. Also take a look into .log/access.log file - you'll see something like this:
127.0.0.1(#7) [date1-date2] "GET /docs/using.html" (152+2362/2362) 200 127.0.0.1(#8) [date1-date2] "GET /docs/yops.css" (152+1163/1163) 200 127.0.0.1(#9) [date1-date2] "GET /docs/yops.png" (135+76/76) 200
First element in each line of the log is IP address of a client (with sequential number of a request in the same persistent connection, in parentheses), second element contains two dates (request begin-end), third one is HTTP request line sent by the client, fourth one is the number if bytes sent to client (http_header+sent/total) and the last one is HTTP status code.
STEP 5. Writing your own pages
Now you can add your own HTML pages into ~/www
directory. When doing this keep in mind the following:
- YOPS only understands quite a few file suffixes: txt, html/htm, css, jpeg/jpg, png and mp3. All static files with any other suffixes or without suffix are sent with "Content-Type" HTTP header set to "application/octet-stream".
- If a pathname begins with a dot request fails with "404 Not found" HTTP message (this is hardcoded). Thus, for ex., .log and .config directories cannot be accessed by clients.
Configuring the server
Configuration is in the .conf/config file.
First note you must restart the server in order to changes take
effect. Just press ^c to terminate the server, edit config then
run the server again.
- tcp_port: TCP port to bind, yes
- send_timeo (seconds): value used in setsockopt(SO_SNDTIMEO)
- recv_timeo (seconds): wait this number of seconds for HTTP-header before sending 408 error
- out_buf_size: size of the buffers used to load static files into memory