• lighttpd支持python


    lighttpd使用fastcgi同时支持php和python

    我们前面已经谈到 用lighttpd的scgi模块部署webpy, 类似于nginx, ligthttpd同样可以使用fasctcgi同时支持php和python

    在 /etc/lighttpd/lighttpd.conf 注释掉
    #server.document-root = “/var/www”
    #server.errorlog = “/var/log/lighttpd/error.log”
    #server.username = “www-data”
    #server.groupname = “www-dat

    在/etc/lighttpd/conf-enabled 创建文件,或者符号链接 mobile.conf (注意要以 .conf结尾),内容如下

    server.modules += (
    	"mod_fastcgi",
    	"mod_accesslog",
    	"mod_rewrite",
    )
    
    server.document-root     = "/home/carbon/stealth"
    server.errorlog                = "/home/carbon/lighty/log/error.log"
    accesslog.filename         = "/home/carbon/lighty/log/access.log"
    
    server.username             = "carbon"
    server.groupname           = "carbon"
    
    fastcgi.server = (
    	".php" => ((
    		"bin-path" => "/usr/bin/php-cgi",
    		"socket" => "/home/carbon/lighty/fastcgi.php.socket",
    		"max-procs" => 1,
    		"bin-environment" => (
    			"PHP_FCGI_CHILDREN" => "4",
    			"PHP_FCGI_MAX_REQUESTS" => "10000"
    		),
    		"bin-copy-environment" => (
    			"PATH", "SHELL", "USER"
    		),
    		"broken-scriptfilename" => "enable"
    	)),
    
    	"" => ((
    		"socket"    => "/home/carbon/lighty/fastcgi.python.socket",
    		"bin-path"  => "/home/carbon/stealth/t.py",
    		"max-procs" => 1,
    		"bin-environment" => (
    			"REAL_SCRIPT_NAME" => ""
    		),
    		"check-local" => "disable"
    		)),
    )
    

    重启后lithttpd

    在/home/carbon/stealth编辑如下文件 i.php

    和 t.py

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import web
    
    web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
    
    urls = ( '/hello', 'hello')
    class hello:
        def GET(self):
            web.header("Content-Type","text/html; charset=utf-8")
            return "Hello world!"
    
    app = web.application(urls, globals())
    if __name__ == "__main__":
        app.run()
    

    用浏览器访问
    http://localhost/i.php

    http://localhost/hello

  • 相关阅读:
    Two Sum
    Binary Tree Preorder Traversal *
    Rotate Array
    Repeated DNA Sequences
    Symmetric Tree
    Path Sum
    Python初学——多线程Threading
    Python初学——窗口视窗Tkinter
    pyinstaller打包多个py文件和去除cmd黑框
    python获取当前路径
  • 原文地址:https://www.cnblogs.com/andyjia/p/4976164.html
Copyright © 2020-2023  润新知