zoukankan      html  css  js  c++  java
  • Flask Quickstart

    code:

    # coding: utf-8
    
    import logging
    from flask import Flask
    
    
    app = Flask(__name__)
    
    
    @app.route('/')
    def index():
        logging.info("here is index")
        return "<span style='color:red'>I am app 1</span>"
    
    
    def main():
        app.run('*', '8080')
    
    
    if __name__ == '__main__':
        main()
    
    

    Development Server

    $ python3 main.py

    $ curl localhost:8080
    <span style='color:red'>I am app 1</span>%
    

    uWSGI

    uwsgi.ini:

    [uwsgi]
    socket = 127.0.0.1:9090
    wsgi-file = main.py
    callable = app
    processes = 4
    threads = 2
    stats = 127.0.0.1:9191
    

    nginx:

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
    
        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;
    
        root /var/www/html;
    
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html;
    
        server_name _;
    
        location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
    
            uwsgi_pass 127.0.0.1:9090;
            include uwsgi_params;
    
            try_files $uri $uri/ =404;
        }
    
        # pass PHP scripts to FastCGI server
        #
        #location ~ .php$ {
        #   include snippets/fastcgi-php.conf;
        #
        #   # With php-fpm (or other unix sockets):
        #   fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        #   # With php-cgi (or other tcp sockets):
        #   fastcgi_pass 127.0.0.1:9000;
        #}
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #   deny all;
        #}
    }
    

    $ uwsgi --ini uwsgi.ini

    $ curl localhost
    <span style='color:red'>I am app 1</span>%
    
  • 相关阅读:
    数组类型
    约瑟夫环问题
    const在c和c++中地位不同
    Makefile学习之路——4
    单链表综合操作
    算法初探——大O表示法
    数据结构实用概念
    Makefile学习之路——3
    翻转字符串
    Makefile学习之路——2
  • 原文地址:https://www.cnblogs.com/ToRapture/p/12941454.html
Copyright © 2011-2022 走看看