Shell The simplest form of http/https

Hello, here is my question - I used to use web server like apache/nginx to setup the port and then redirect it to some file like geteway.php or whole complex framework like composed one. How can I do the same thing with sh script and without server program like nginx. How it was done it days before pkg and high speed internet, with native unix tools? Just wondering actually.

Thank a lot. peace
 
You can't, shells don't support listening on sockets. You can of course leverage tools like traditional inetd(8), or nc(1) or socat(1) to interface with sockets, but then you'll have to implement HTTP in shell script, which will be a real PITA.
 
Geezer please, explain the difference between C and C? ;)

Well, I did that, just for fun. Without using libraries, you have to "solve" lots of things yourself:
  • Handling many clients in parallel. The classic fork() model has many drawbacks: processes can't communicate with each other easily, and forking many of them comes with a cost. I decided for pselect(2), although this doesn't scale perfectly either. Better alternatives are platform-dependent, or you have to use a library...
  • Handling parallel execution for multiple requests. I ended up implementing my very own thread pool for that
  • Of course, parsing HTTP requests and formatting HTTP responses. Can be done using primitives like (char) pointers and some "string" functions from the C standard library...
 
Like Zirias said, you can use netcat to implement a simple web server. Not a huge package and no need to compile anything either.
 
My company didn't use shell scripts for this but we did do all our web programming in C. We did start with Apache, switched to nginx, and finally landed on h2o server. However, parts of the communication did involve using a simple server in C. We also talked to the built in server with node.js. FreeBSD was our tool for doing everything. We intentionally avoided other people's code as much as possible.

Nowadays, it's more difficult to serve web pages without server software if you intend to use HTTP/2 or HTTP/3 due to the multiplexing of data transfer. And many of the payment processors required node software.
 
The idea is to make everything as simple as possible and not to "deal" with huge packages, and not to compile anything at all.

If you use high level, then you have to deal with huge libraries.

If you use low level, then you have to compile.
 
I've installed php8.0 and apache2 with some extension, the code inside is like two infinities (src I mean), to cryptographic inside) Now I need to figure out how to deal with xml that I'm going to handle with posts, that the hardest mission(

Can't really get familiar with oop php wrapping, not to being criticized by someone, how to be proud of own bad code?
 
The suggestions for inetd are spot on.

However, inetd does not handle TLS. For HTTPS, you can run nginx as a proxy server and run your inetd service on localhost.
 
Back
Top