当前位置: 代码迷 >> 综合 >> uwsgi on nginx (by quqi99)
  详细解决方案

uwsgi on nginx (by quqi99)

热度:43   发布时间:2023-12-13 08:59:09.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 onlisten      8000;#server_name .example.com; # substitute your machine's IP address or FQDNserver_name 192.168.99.135charset     utf-8;# max upload sizeclient_max_body_size 75M;   # adjust to tastelocation / {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     #djangocurl http://192.168.99.135:8000/