Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's difference between a simple webserver and Apache server?

Here the simple webserver means a server that deal with simple HTTP request, just like the following one:

import BaseHTTPServer
class WebRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path == ‘/foo’: 
            self.send_response(200)
            self.do_something()
        else:
            self.send_error(404)

    def do_something(self):
        print ‘hello world’

server = BaseHTTPServer.HTTPServer((’127.0.0.1′,8080), WebRequestHandler)    
server.serve_forever()

Despite of dealing with request of POST,PUT,DELETE methods, what is the difference between this simple server with Apache Web Server? Or in other words, if i want to use python to implement a server which can be put into use of business, what also should i do?

It'd be greatly appreciated if the big picture of Apache Server is shown.

like image 713
Helium Avatar asked Apr 17 '11 13:04

Helium


People also ask

Is Apache server a web server?

The Number One HTTP Server On The Internet The Apache HTTP Server ("httpd") was launched in 1995 and it has been the most popular web server on the Internet since April 1996.

What is the difference between webserver and server?

Q: What is the difference between an application server and a Web server? A: A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols.

What is the purpose of Apache on webserver?

As a Web server, Apache is responsible for accepting directory (HTTP) requests from Internet users and sending them their desired information in the form of files and Web pages. Much of the Web's software and code is designed to work along with Apache's features.

What is a web server simple?

Definition: A web server is a computer that runs websites. It's a computer program that distributes web pages as they are requisitioned. The basic objective of the web server is to store, process and deliver web pages to the users. This intercommunication is done using Hypertext Transfer Protocol (HTTP).


2 Answers

Or in other words, if i want to use python to implement a server which can be put into use of business, what also should i do?

There are already python-based web servers, such as CherryPy (which I think is intended to be a web server solution on the same stack level as Apache; it is more python-based though, and Apache has been around a lot longer).

If you wish to write a lightweight extremely simple webserver from scratch, there is probably nothing wrong with using BaseHTTPServer, other than perhaps a few outstanding design issues (I hear race conditions might permanently clog a socket until a thread dies).

Though I would not recommend it (alone) for business, some of the big boys use BaseHTTPServer with a bit of extra machinery: http://www.cherrypy.org/browser/trunk/cherrypy/_cphttpserver.py?rev=583

To elaborate, Apache is the industry standard. It has a plethora of configuration options, a security team, vulnerability mailing lists I think, etc. It supports modules (e.g. mod_python). Python-based web servers also support python-based modules (maybe they might allow you access to non-python things) via something called a WSGI stack; a WSGI application can run on any python-based web server (and Apache too, which also has a modwsgi); I think they are narrower in scope than Apache modules.

Apache module examples: http://httpd.apache.org/docs/2.0/mod/

WSGI examples (not a valid comparison): http://wsgi.org/wsgi/Middleware_and_Utilities

I might code my own webserver if I'm doing something extremely lightweight, or if I needed massive control over webserver internals that the module interfaces could not provide, or if I was doing a personal project. I would not code my own server for a business unless I had significant experience with how real-world web servers worked. This is especially important from a security vulnerability point-of-view.

For example, I once wrote a web-based music player. I used a BaseHTTPServer to serve music out of a sandbox I had written to ensure that people couldn't access arbitrary files. Threading was a nightmare. (I recall a bug where you needed to pass special arguments to Popen since threading caused an implicit fork which would cause hangs on dangling file descriptors.) There were other various issues. The code needed to be refactored a lot. It can be very worthwhile for a personal project, but is a significant undertaking and not worth it for a business that just needs a website.

I know two startups who have been content using Pylons (using Paste) or Turbogears (using CherryPy) in the past, if you're looking for a lightweight python web server stack. Their default template systems are lacking though. The choice between Apache and a leaner more python-based web server may also depend on the skillset of your co-developers.

like image 156
ninjagecko Avatar answered Oct 19 '22 16:10

ninjagecko


Apache is written in C and designed to be scalable while BaseHTTPServer is meant for local/testing/debugging environments.

So you shouldn't use BaseHTTPServer for any production sites.

like image 39
ThiefMaster Avatar answered Oct 19 '22 16:10

ThiefMaster