这篇文章主要介绍Python如何实现WEB,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
创新互联专注于企业营销型网站建设、网站重做改版、昌宁网站定制设计、自适应品牌网站建设、H5开发、电子商务商城网站建设、集团公司官网建设、外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为昌宁等各大城市提供网站开发制作服务。
Python实现WEB测试环境:
服务器配置: 4 x Intel(R) Xeon(R) CPU E5405 @ 2.00GHz, 4G内存, 操作系统: CentOS 5.3 x86_64
nginx前端 + 4 tornado(0.2) web process
tornado: http://www.tornadoweb.org (已被墙)
Python实现WEB测试场景:
http get请求,服务器端直接返回"hello world"
Python实现WEB代码及nginx配置:
main.py: #!/usr/bin/python # -*- coding: utf-8 -*- """web main""" from tornado.httpserver import HTTPServer from tornado.ioloop import IOLoop from tornado.web import RequestHandler, Application, authenticated #from rockps.auth import AuthHandler class MainHandler(RequestHandler): def get(self): self.write("hello world") settings = { } application = Application([ (r"/", MainHandler), ], **settings) if __name__ == "__main__": http_server = HTTPServer(application) http_server.listen(8081) IOLoop.instance().start() nginx.conf: user root; worker_processes 1; error_log /var/nginx_error.log; pid /var/run/nginx.pid; events { worker_connections 51200; use epoll; } http { # Enumerate all the Tornado servers here upstream frontends { server 127.0.0.1:8081; server 127.0.0.1:8082; server 127.0.0.1:8083; server 127.0.0.1:8084; } #include /etc/nginx/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access22.log; keepalive_timeout 65; proxy_read_timeout 200; sendfile on; tcp_nopush on; tcp_nodelay on; gzip on; gzip_min_length 1000; gzip_proxied any; gzip_types text/plain text/html text/css text/xml application/x-javascript application/xml application/atom+xml text/javascript; # Only retry if there was a communication error, not a timeout # on the Tornado server (to avoid propagating "queries of death" # to all frontends) proxy_next_upstream error; server { listen 8085; # Allow file uploads client_max_body_size 50M; location ^~ /static/ { root /var/www; if ($query_string) { expires max; } } location = /favicon.ico { rewrite (.*) /static/favicon.ico; } location = /robots.txt { rewrite (.*) /static/robots.txt; } location / { proxy_pass_header Server; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Scheme $scheme; proxy_pass http://frontends; } } }
以上是“Python如何实现WEB”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
分享题目:Python如何实现WEB
URL分享:https://www.cdcxhl.com/article42/jedohc.html
成都网站建设公司_创新互联,为您提供电子商务、网站制作、服务器托管、网页设计公司、品牌网站制作、网站策划
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联