這篇文章主要介紹Python如何實(shí)現(xiàn)WEB,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
創(chuàng)新互聯(lián)專注于企業(yè)營銷型網(wǎng)站建設(shè)、網(wǎng)站重做改版、昌寧網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5開發(fā)、電子商務(wù)商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為昌寧等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。
Python實(shí)現(xiàn)WEB測(cè)試環(huán)境:
服務(wù)器配置: 4 x Intel(R) Xeon(R) CPU E5405 @ 2.00GHz, 4G內(nèi)存, 操作系統(tǒng): CentOS 5.3 x86_64
nginx前端 + 4 tornado(0.2) web process
tornado: http://www.tornadoweb.org (已被墻)
Python實(shí)現(xiàn)WEB測(cè)試場(chǎng)景:
http get請(qǐng)求,服務(wù)器端直接返回"hello world"
Python實(shí)現(xiàn)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如何實(shí)現(xiàn)WEB”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!