sudo apt-get install lighttpd sudo nano /etc/lighttpd/lighttpd.conf
#mod_cgi shoud be on server.modules = ( "mod_access", "mod_alias", "mod_compress", "mod_redirect", "mod_cgi", "mod_rewrite", ) #rule enables cgi script cgi.assign = (".py" => "/usr/bin/python")
print "Content-Type: text/html\n\n" print "Hello World!"
#! /usr/bin/python # import web urls = ( '/', 'index',) class index: def GET(self): return "Hello, world!" if __name__ == "__main__": web.application(urls, globals()).run()
#! /usr/bin/python # def myapp(environ, start_response): status = '200 OK' response_headers = [('Content-type','text/plain')] start_response(status, response_headers) return ['Hello World!\n']
#! /usr/bin/python import os import sys def run_with_cgi(application): environ = dict(os.environ.items()) environ['wsgi.input'] = sys.stdin environ['wsgi.errors'] = sys.stderr environ['wsgi.version'] = (1, 0) environ['wsgi.multithread'] = False environ['wsgi.multiprocess'] = True environ['wsgi.run_once'] = True if environ.get('HTTPS', 'off') in ('on', '1'): environ['wsgi.url_scheme'] = 'https' else: environ['wsgi.url_scheme'] = 'http' headers_set = [] headers_sent = [] def write(data): if not headers_set: raise AssertionError("write() before start_response()") elif not headers_sent: status, response_headers = headers_sent[:] = headers_set sys.stdout.write('Status: %s\r\n' % status) for header in response_headers: sys.stdout.write('%s: %s\r\n' % header) sys.stdout.write('\r\n') sys.stdout.write(data) sys.stdout.flush() def start_response(status, response_headers, exc_info=None): if exc_info: try: if headers_sent: raise exc_info[0], exc_info[1], exc_info[2] finally: exc_info = None elif headers_set: raise AssertionError("Headers already set!") headers_set[:] = [status, response_headers] return write result = application(environ, start_response) try: for data in result: if data: write(data) if not headers_sent: write('') finally: if hasattr(result, 'close'): result.close()
#! /usr/bin/python include wsgi def myapp(environ, start_response): status = '200 OK' response_headers = [('Content-type','text/plain')] start_response(status, response_headers) return ['Hello World!\n'] if __name__ == '__main__': wsgi.run_with_cgi(myapp)
#! /usr/bin/python import wsgiref.handlers def myapp(environ, start_response): status = '200 OK' response_headers = [('Content-type','text/plain')] start_response(status, response_headers) return ['Hello World!\n'] if __name__ == '__main__': wsgiref.handlers.CGIHandler().run(myapp)
sudo apt-get install python-flup
#! /usr/bin/python import flup.server.fcgi def myapp(environ, start_response): status = '200 OK' response_headers = [('Content-type','text/plain')] start_response(status, response_headers) return ['Hello World!\n'] if __name__ == '__main__': flup.server.fcgi.WSGIServer(myapp).run()
#! /usr/bin/python import web urls = ( '/', 'index', ) class index: def GET(self): return "Hello World!" if __name__ == '__main__': web.application(urls, globals()).run()
web.application(urls, globals()).cgirun()
# mod_rewrite configuration. url.rewrite-once = ( "^/favicon.ico$" => "/favicon.ico", "^/(.*)$" => "app.py/$1" ,)
import cgitb cgitb.enable()
Source: https://habr.com/ru/post/256481/
All Articles