uwsgi on nginx (by quqi99)

作者:張華 發表於: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/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章