uwsgi on nginx (by quqi99)

python 专栏收录该内容
4 篇文章 0 订阅

作者:张华 发表于:2020-06-03
版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明

set up virtualenv

sudo apt install build-essential python3-dev libpython3.8-dev python3-testresources -y
pip install --upgrade setuptools
pip install --upgrade --force-reinstall pip virtualenv
#virtualenv uswgitest
sudo apt install python3-venv && python3 -m venv uwsgitest
source ~/uwsgitest/bin/activate

#or not use virtualenv
apt install python3-pip -y
pip3 install uwsgi
#uwsgi --socket unix:///var/snap/xxx-rbac/224/uwsgi/uwsgi.sock --module crbs.wsgi --chmod-socket=666
#snap restart xxx-rbac.uwsgi && snap restart xxx-rbac.nginx

web client <-> uWSGI <-> Python

cd /tmp
bash -c 'cat > /tmp/test.py' << EOF
def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"] # python3
EOF
curl http://192.168.99.135:8000

web client <-> uWSGI <-> Django

pip install django
django-admin startproject mysite
cd mysite
sed -i "s/ALLOWED_HOSTS = \[\]/ALLOWED_HOSTS = \[\"192\.168\.99\.135\"\]/g" ./mysite/settings.py
#python manage.py runserver 0.0.0.0:8000
uwsgi --http :8000 --module mysite.wsgi
curl http://192.168.99.135:8000

web client <-> the web server <-> the socket <-> uWSGI <-> Python

sudo apt-get purge nginx nginx-common nginx-full && sudo apt install nginx -y
sudo systemctl restart nginx
ls /var/www/html/
curl http://192.168.99.135:80
wget https://raw.githubusercontent.com/nginx/nginx/master/conf/uwsgi_params -O /tmp/mysite/uwsgi_params
bash -c 'cat > /tmp/mysite/mysite_nginx.conf' << EOF
upstream djangosite {
    server unix:///tmp/mysite//mysite.sock; # for a file socket
    #server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
server {
    # the port your site will be served on
    listen      8000;
    #server_name .example.com; # substitute your machine's IP address or FQDN
    server_name 192.168.99.135
    charset     utf-8;
    # max upload size
    client_max_body_size 75M;   # adjust to taste
    location / {
        uwsgi_pass  djangosite;
        include     /tmp/mysite/uwsgi_params; # the uwsgi_params file you installed
    }
}
EOF
sudo ln -s /tmp/mysite/mysite_nginx.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx
sudo usermod -a -G www-data $USER
#uwsgi --socket :8001 --wsgi-file /tmp/test.py
uwsgi --socket /tmp/mysite/mysite.sock --wsgi-file /tmp/test.py --chmod-socket=666 #app
uwsgi --socket /tmp/mysite/mysite.sock --module mysite.wsgi --chmod-socket=666     #django
 
curl http://192.168.99.135:8000/
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 打赏
    打赏
  • 扫一扫,分享海报

参与评论 您还未登录,请先 登录 后发表或查看评论
©️2022 CSDN 皮肤主题:Age of Ai 设计师:meimeiellie 返回首页

打赏作者

quqi99

你的鼓励就是我创造的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值