一:安裝uwsgijavascript
pip3 install uwsgicss
二:進入項目目錄下,建立uwsgi.ini配置文件html
[uwsgi] # 使用nginx鏈接時使用功能,上線時才使用socket,指定項目執行的端口號 socket=127.0.0.1:8000 # 項目目錄 chdir=/data/webapp/otp_manage # 項目中wsgi.py文件的目錄,相對於項目目錄 wsgi-file=otp_manage/wsgi.py # 最大進程 workers=3 # 開啓主進程 master=True # 退出、重啓時清理文件 vacuum = true # pidfile=uwsgi.pid daemonize=uwsgi.log
三:啓動服務java
uwsgi在哪一個目錄啓動,就會在哪一個目錄生成uwsgi.pid和uswgi.log文件,故須要切換到項目目錄下執行
啓動:uwsgi --ini uwsgi.ini
中止:uwsgi --stop uwsgi.pid
重啓:uwsgi --reload uwsgi.pid
強制中止:killall -8 uwsgi
這裏咱們啓動uwsgi服務,能夠經過ps -ef | grep uwsgi看到已經有四個uwsgi服務啓動。node
四:安裝Nginxpython
tar zxf nginx-1.8.1.tar.gz cd nginx-1.8.1 ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre make && make install
五編寫nginx.conf配置文件nginx
user www www; worker_processes 2; error_log /usr/local/nginx/logs/nginx_error.log notice; pid /usr/local/nginx/sbin/nginx.pid; worker_rlimit_nofile 204800; events { use epoll; worker_connections 204800; } http { include mime.types; default_type application/octet-stream; charset utf-8; server_tokens off; server_names_hash_bucket_size 512; client_header_buffer_size 512k; large_client_header_buffers 64 512k; client_max_body_size 100m; proxy_ignore_client_abort on; sendfile on; tcp_nopush on; keepalive_timeout 120; keepalive_requests 1024; fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=30d max_size=3096m; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 4k; fastcgi_buffers 8 4k; fastcgi_busy_buffers_size 8k; fastcgi_temp_file_write_size 8k; # fastcgi_cache TEST; fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid 301 1d; fastcgi_cache_valid any 1m; fastcgi_cache_min_uses 1; fastcgi_cache_use_stale error timeout invalid_header http_500; open_file_cache max=204800 inactive=20s; open_file_cache_min_uses 1; open_file_cache_valid 60s; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 16 64k; gzip_http_version 1.1; gzip_comp_level 6; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; gzip_vary on; log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '"$upstream_addr" "$upstream_status" "$request_time" "$upstream_response_time" $bytes_sent $request_length'; include /usr/local/nginx/conf/vhosts/*.conf; }
六:建立vhosts目錄。編寫.conf文件web
server { listen 80; server_name localhost; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8000; uwsgi_param UWSGI_SCRIPT otp_manage.wsgi; # /data/webapp/otp_manage 是項目目錄 uwsgi_param UWSGI_CHDIR /data/webapp/otp_manage; index index.html index.htm; client_max_body_size 35m; } location /static { client_max_body_size 35m; alias /data/webapp/otp_manage/statics; } }
啓動Nginx 進行訪問便可json