{"id":23893342,"url":"https://github.com/sumpygump/nanoweb","last_synced_at":"2025-02-23T06:12:32.798Z","repository":{"id":19035651,"uuid":"22260233","full_name":"sumpygump/nanoweb","owner":"sumpygump","description":"Super simple static web server (from nweb23)","archived":false,"fork":false,"pushed_at":"2023-04-08T03:36:25.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-04T14:17:44.361Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sumpygump.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-25T14:45:43.000Z","updated_at":"2022-12-21T01:35:33.000Z","dependencies_parsed_at":"2023-01-11T20:30:34.634Z","dependency_job_id":null,"html_url":"https://github.com/sumpygump/nanoweb","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumpygump%2Fnanoweb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumpygump%2Fnanoweb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumpygump%2Fnanoweb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sumpygump%2Fnanoweb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sumpygump","download_url":"https://codeload.github.com/sumpygump/nanoweb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240275929,"owners_count":19775616,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-04T14:17:49.254Z","updated_at":"2025-02-23T06:12:32.774Z","avatar_url":"https://github.com/sumpygump.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nanoweb\n\nSuper simple static web server (forked from nweb23)\n\n## Building\n\nRun `make`\n\n## Usage\n\nFrom command line run the following:\n\n```\nnanoweb \u003cport\u003e \u003croot_path\u003e\n```\n\nExample:\n\n```\nnanoweb 8181 /var/www\n```\n\n-----------------\n\n## Historical README documentation below\n\n### nweb README for version 23\n\n1) Bug fixed - was duplicating errors in the log file. Thanks to Kieran Grant\n    for stopping this and pointing out the fix.\n\n2) Added support for `favicon.ico` - if nothing else this will stop annoying\n    errors in the log file.  Most browsers on first encountering a webpage also ask\n    for this file.  The name mean favourite icon - Wikipedia has more on this.  It\n    is a tiny Bit Map image (normally called .bmp and BMP editors can be used to\n    create one - I used Windows Paint) I uses a very simple 16x16 pixels and 256\n    colour to keep the size and complexity down.  To add support I added `.ico`\n    file extension to the allowed extensions data structure and the sample\n    `favicon.ico` file.  This is then displyed by the browser at the little graphic\n    next to the URL. The one I made looks like this with a blue background.\n\t```\n\t+---+\n\t|n  |\n\t|Web|\n\t+---+\n\t```\n\n3) As item 1 removed a few lines, I managed to add item 2 and still stay at 200 lines.\n\nThe code:\n- nweb23.c -- the source code version 23\n- client.c -- sample client end source code\n\n*nweb* executable files for:\n- AIX 6.1 TL7 fnd AIX 7 TL1   POWER \n- Ubuntu 12.4 for `x86_64`     Intel/AMD 64 bit\n- Ubuntu 12.4 for `x86_32`     Intel/AMD 32 bit\n- Fedora 17 Linux for `x86_64`  Intel/AMD 64 bit\n- OpenSUSE 12.1 for `x86_64`    Intel/AMD 64 bit\n- Red Hat RHEL 6.3 for `x86_64` Intel/AMD 64 bit\n- SUSE SLES 11 for `x86_64`    Intel/AMD 64 bit\n- Debian Squeeze for ARM on Raspberry Pi \n\nMinimum test website\n- index.html  -- test very bascis web page \n- nigel.jpg   -- test image file\n- favicon.ico -- the favourite icon bit map file\n\n### nweb README for version 22\n\nThe nweb download file includes: \n\n**README** -- this file\nThis file contains lots of hints \u0026 tips on compiling and running the *nweb* code.\n\n**nweb22.c**\nThe 22 is the version number. *nweb* stands for Nigel's Web server but I some\ntimes call it a *nano web server* (i.e. very small).\n\nThis *nweb* is a web server that will respond to simple web browser requests for\nstatic files.  This version is exactly 200 lines long.  I started with a target\n100 lines and it worked fine too but then added comments, file type checks,\nsecurity checks, sensible directory checks and logging.\n\nTo compile this you need a basic C compiler use: `cc nweb22.c -o nweb`\nIf you want it to run faster you could include optimisation: \n`cc -O2 nweb22.c -o nweb`\n\nThen to run it as root for the test files:\n1) Place the `index.html` file and `nigel.jpg` in to a sensible directory \n\tNote: not any system directories like `/` or `/tmp` \n\tA directory in `/home` would be a good idea - below we use `/home/nigel/web`\n\n2) Make these files readable\n\t`chmod ugo+r /home/nigel/web`\n\n3) Decide the port number\n\tPort number 80 is the web server default and assumed by web browsers.\n\tyou might have to be the root user to use that  port number.\n\tIf the machine is already running a web server then it will \n\tprobably be using port 80 so you can't us 80.\n\tI test using port 8181 but you have to make up your mind.\n\n4) Start the nweb server:  `/home/nigel/bin/nweb 80   /home/nigel/web`\n\tor if using 8181   `/home/nigel/bin/nweb 8181 /home/nigel/web`\n\n\tIf the program and files are all in `/home/nigel/all`\n\tYou could use:\n\t```\n\tcd /home/nigel/all\n\trm -f nweb.log\n\t./nweb 80 .\n\tps -ef | grep nweb \n\ttail -f nweb.log\n\t```\n\n\tSee below for explanations for the rm, ps and tail\n\n5) Note that any suitable files in the directory 2nd argument above could be\n    served by the *nweb* web server - so don't have anything secret in that\n    directory!\n\n6) Use a browser to test it if using port 80 on a machine hostname \n    for abc123.com. Point your browser to: http://abc123.com/index.html\n    If using port 8181, then use http://abc123.com:8181/index.html\n\n7) Running *nweb* as a regular user. You can run *nweb* as a regular user on\n    some operating systems but not all.  I find using sudo works on some:\n    ```\n    sudo /home/nigel/bin/nweb 80   /home/nigel/web\n    ```\n\n    If you try and the log file reports socket connections errors worth \n\ttrying the 8181 port or higher numbers.  This is because \n\tlower port numbers are reserved for root user use.\n\n8) VERY IMPORTANT.  nweb will behave like a daemon process, so it disconnects\n    from the users command shell, goes into the background, closes input and output\n    I/O \u0026 protects itself from you logging off.  It will look like it stopped, when\n    it is in fact still running in the background - check with `ps -ef | grep nweb`\n    Also note you will not see errors or warnings messages, they go in the log\n    file.\n\n    Look in the `nweb.log` file for problems starting up or browsers connecting\n    and requesting pages with: `cat nweb.log` or: `tail -f nweb.log`\n\n    I find it good to remove the `nweb.log` before I start *nweb* or it is easy\n    to get confused with previous error messages in the log.\n\n9) As *nweb* runs as a daemon process it will try to run forever and not\n    connected to your user or terminal session.  Logging out will not effect it. To\n    stop *nweb* you have to stop it by a KILL signal.  Find the *nweb* process\n    with: `ps -ef | grep nweb` Then use: `kill -9 PID` to stop the *nweb* process.\n\n10) `nweb.log` Log file - what to look for\n    **Good example**\n    Here is an edited down sample `nweb.log` file.  Note the first line:\n    \"starting\" looks good as there is no following error.\n    ```\n    INFO: nweb starting:8181:8913126\n\tINFO: request:GET /index.html HTTP/1.1 [[1KB of deleted request stuff here]]:2\n\tINFO: SEND:index.html:2\n\tINFO: Header:HTTP/1.1 200 OK\n\tServer: nweb/21.0\n\tContent-Length: 239\n\tConnection: close\n\tContent-Type: text/html\n\n\tINFO: request:GET /nigel.jpg HTTP/1.1  [[1KB of deleted request stuff here]]:3\n\tINFO: SEND:nigel.jpg:3\n\tINFO: Header:HTTP/1.1 200 OK\n\tServer: nweb/21.0\n\tContent-Length: 10184\n\tConnection: close\n\tContent-Type: image/jpg\n    ```\n\n    **Bad example**\n    A failure to start due to the port number is not aallowed or in use looks like:\n\n    ```\n    INFO: nweb starting:80:8323296\n    ERROR: system call:bind Errno=13 exiting pid=8323296\n    ```\n\n**client.c**\n\nThis client.c program is designed to fake being a web browser.  It sends the\nexpected requests to the web server over a network socket connection and\ndisplays the results as text rather than graphically displaying the results.\nIn the code you will have to change the two lines as below to match your web\nserver or nweb server.\n\n```\n/* YOU WILL HAVE TO CHANGE THESE TWO LINES TO MATCH YOUR CONFIG */\n#define PORT        8181\t\t/* Port number as an integer - web server default is 80 */\n#define IP_ADDRESS \"192.168.0.8\"\t/* IP Address as a string */\n```\n\nThe default is to request the `/index.html` from the web server. If you want to\nrequest another file then change the GET line as below:\n```\nchar *command = \"GET /index.html HTTP/1.0 \\r\\n\\r\\n\" ;\n```\n\nTo, for example:\n```\nchar *command = \"GET /nigel.jpg HTTP/1.0 \\r\\n\\r\\n\" ;\n```\n\nThen compile the program with: `cc client.c -o client`\n\nI save the output in to a file as putting a non-test file like .jpg to the\nterminal screen can cause chaos: `client \u003eoutput`\n\nThen edit the output file: `vi output`\n\nIn real life, the interaction of web browser and web server can be much more complex.\n\n1. The web browser can tell the web server about its name, version and capabilities.\n2. The web server can send complex file types line JavaScript or Java programs or other active components.\n3. They can maintain a longer connection over the socket for efficiency.\n4. Below is an example of my Firefox brower requesting an `index.html` file. \n\nI have added newline characters to make it readable - it is 1300 bytes long! I\nhave no idea what most of it is about. You will have to read the The World Wide\nWeb Consortium (W3C) at http://www.w3.org for all the details.\n\n```\nGET /index.html HTTP/1.1**Host: myserver.home.com:80**User-Agent: Mozilla/5.0 \n(W indows; U; Windows NT 5.1; en-GB; rv:1.9.2.28) Gecko/20120306 Firefox/3.6.28 \n(.NET CLR 3.5.30729)**Ac cept: image/png,image/*;q=0.8,*/*;q=0.5**Accept-Language: \nen-gb,en;q=0.5**Accept-Encoding: gzip,defla te**Accept-Charset: ISO-8859-1,utf-8;\nq=0.7,*;q=0.7**Keep-Alive: 115**Connection: keep-alive**Referer: \nhttp://myserver.uk.home.com:8181/index.html**Cookie: \n__utma=101107545.1790272076.1316019590.13289002 55.1328908680.164; \n__utmz=101107545.1328566199.157.46.utmcsr=t.co|utmccn=(referral)|utmcmd=referral|\nu tmcct=/iTJx4DO1; UnicaNIODID=ZBr8gm79vIG-XKeoGGb; W3SSO_ACCESS=abc.home.com; \nISP=70fdfc95 d93011d783e4de784ea97766-70fdfc95d93011d783e4de784ea97766-f67749a8b899e8ceed7e940b8c4bf189; \nProf ile=2000121913394303111032836125|EN|866|866.BDF|en-GB; \n__unam=693fb60-1337f162b72-11770d11-5; WLS_ intra_USERID=nigel@hotmail.com; \nipcInfo=cc%3Duk%3Blc%3Den%3Bac%3Dall; iwm1p=214617669; bprememberme=nigel@ hotmail.com; \nEPSPROFILE=EE2355DFE16AE020BE6C62FCB6BF5602; DWPERM=Xa.2/Xb.Xzso3-U35t8RWKvqBreGaQMgsP_RG \nFl1124oIt-L-OPJIdSautkBN0D4NUp9JLlpUqPqB6CWOo-pgrJwhxNvvSfPAajgetaA2MOYwHfQPXPTRG9zwOMMR57EHQtXhOy5Om yzanyZthvVClm6uxvbwh0isEQ2Mm_9g2l7NjcA3RJdjuLaB3qlljOmyVuhDjBkgdNEb3PgYcCpbiu1FUzXrhPalhgsbAj7NBkaY88 Yyg/Xc./Xd./Xf./Xg.1696801 \n```\n\nI hope this has been instructive, thanks, Nigel Griffiths\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumpygump%2Fnanoweb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsumpygump%2Fnanoweb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumpygump%2Fnanoweb/lists"}