Apache provides lots of to user, these modules provide lots of directives you can use in conf file through these, user can modify the behavior of apache like modify request, response header etc.
# just add a symbol link in /etc/apache2/mods-enabled/ to /etc/apache2/mods-available/ $ ln -s /etc/apache2/mods-available/macro.load /etc/apache2/mods-enabled/
create web server by python
In this case, you can add any header and any body to client, fully controlled by your self.
define your own simple server
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#! /usr/bin/env python3.5 from http.server import HTTPServer, BaseHTTPRequestHandler classSimpleHTTPRequestHandler(BaseHTTPRequestHandler): defdo_GET(self): # only add status line, server and date headers self.send_response(200)
from http.server import SimpleHTTPRequestHandler from socketserver import TCPServer
classGetHandler(SimpleHTTPRequestHandler): defdo_GET(self): # static web server, rewrite like above for dynamic SimpleHTTPRequestHandler.do_GET(self)
httpd = TCPServer(("", 8000), GetHandler)
httpd.serve_forever()
FAQ
enable keep-alive
edit /etc/apache2/apache2.conf with below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# # KeepAlive: Whether or not to allow persistent connections (more than # one request per connection). Set to "Off" to deactivate. # KeepAlive On
# MaxKeepAliveRequests: The maximum number of requests to allow # during a persistent connection. Set to 0 to allow an unlimited amount. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 100
# # KeepAliveTimeout: Number of seconds to wait for the next request from the # same client on the same connection. when timeout, apache will close the connection # KeepAliveTimeout 500
return application/json for xx.json file
1
AddType 'application/json; charset=UTF-8' .json
modify response header
modify header feature is provided by mod_headers.so, first you should enable such module by ln -s /etc/apache2/mods-available/headers.load /etc/apache2/mods-enabled/
1 2
# apache.conf Header set Host "www.test.com";
Remember to restart service service apache2 restart