Python高效能網路架構(一)__Python

來源:互聯網
上載者:User
Linux+Nginx+uWSGI

1.安裝nginx

sudo apt install nginxsudo service nginx start

2.縱覽nginx的配置,類似tomcat

# 程式檔案:/usr/sbin/nginx############################################################################# 全域設定檔:/etc/nginx/nginx.confuser www-data;  #定義運行nginx的使用者worker_processes auto;  #進程數pid /run/nginx.pid;worker_rlimit_nofile 65535; #每個nginx進程可以開啟的最大檔案數events {    worker_connections 768; #每個nginx進程允許的最大用戶端串連數    multi_accept off;   #在建立一個新串連後調用accept()來接受盡量多的串連}http {    ##    # Basic Settings    ##    sendfile on;    #是否允許檔案上傳    tcp_nopush on;  #防止網路阻塞    tcp_nodelay on; #防止網路阻塞    keepalive_timeout 65;   #允許的用戶端長串連秒數    types_hash_max_size 2048;   #散列表大小,佔用空間和路由速度正相關    # server_tokens off;    # server_names_hash_bucket_size 64;    # server_name_in_redirect off;    include /etc/nginx/mime.types;    default_type application/octet-stream;    ##    # SSL Settings    ##    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE    ssl_prefer_server_ciphers on;    ##    # Logging Settings    ##    access_log /var/log/nginx/access.log;    error_log /var/log/nginx/error.log;    ##    # Gzip Settings    ##    gzip on;    gzip_disable "msie6";    # gzip_vary on;    # gzip_proxied any;    # gzip_comp_level 6;    # gzip_buffers 16 8k;    # gzip_http_version 1.1;    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;    ##    # Virtual Host Configs    ##    #載入網站設定檔    include /etc/nginx/conf.d/*.conf;    include /etc/nginx/sites-enabled/*;}#mail {#   # See sample authentication script at:#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript##   # auth_http localhost/auth.php;#   # pop3_capabilities "TOP" "USER";#   # imap_capabilities "IMAP4rev1" "UIDPLUS";##   server {#       listen     localhost:110;#       protocol   pop3;#       proxy      on;#   }##   server {#       listen     localhost:143;#       protocol   imap;#       proxy      on;#   }#}###################################################################################### 訪問記錄檔:/var/log/nginx/access.log###################################################################################### 錯誤記錄檔檔案:/var/log/nginx/error.log###################################################################################### 網站設定檔:/etc/nginx/sites-enabled/default### You should look at the following URL's in order to grasp a solid understanding# of Nginx configuration files in order to fully unleash the power of Nginx.# http://wiki.nginx.org/Pitfalls# http://wiki.nginx.org/QuickStart# http://wiki.nginx.org/Configuration## Generally, you will want to move this file somewhere, and start with a clean# file but keep this around for reference. Or just disable in sites-enabled.## Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.### Default server configuration#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 /usr/share/nginx/html; #配置http根目錄    # Add index.php to the list if you are using PHP    index index.html index.htm; #配置根目錄中的預設頁面    server_name localhost;    location /user/ {        # First attempt to serve request as file, then        proxy_pass http://127.0.0.1:8080;    }    # as directory, then fall back to displaying a 404.    error_page 404 /404.html;    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000    #    #location ~ \.php$ {    #   include snippets/fastcgi-php.conf;    #    #   # With php7.0-cgi alone:    #   fastcgi_pass 127.0.0.1:9000;    #   # With php7.0-fpm:    #   fastcgi_pass unix:/run/php/php7.0-fpm.sock;    #}    # deny access to .htaccess files, if Apache's document root    # concurs with nginx's one    #    #location ~ /\.ht {    #   deny all;    #}}# Virtual Host configuration for example.com## You can move that to a different file under sites-available/ and symlink that# to sites-enabled/ to enable it.##server {#   listen 80;#   listen [::]:80;##   server_name example.com;##   root /var/www/example.com;#   index index.html;##   location / {#       try_files $uri $uri/ =404;#   }#}

3.uWsgi配置:
如果運行uwsgi,可以嘗試運行以下命令,安裝編譯
pip install uwsgi -I –no-cache-dir
如果還是不行,那就再運行這個命令
sudo apt-get install libpcre3 libpcre3-dev

4.可能遇到的問題
配置一個指令碼返回到前端
uwsgi -s :9090 -w webapp.py
若顯示invalid block size,添加參數
uwsgi -b 8192
或者修改uwsgi啟動設定檔,比如uwsgi.ini添加以下配置:
buffer-size = 8192

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.