nginx反向代理uwsgi django服務器搭建總結

1.安裝python、django、虛擬環境
參考帖子:安裝python django
https://blog.csdn.net/a249900679/article/details/51527200html

安裝配置虛擬環境:
https://www.cnblogs.com/technologylife/p/6635631.html
其餘參考網頁:
https://www.cnblogs.com/levelksk/p/7921066.html
https://blog.csdn.net/m0_37687051/article/details/75267679
2. 安裝uwsgi
pip install uwsgi
3. 安裝nginx
wget http://nginx.org/download/nginx-1.13.7.tar.gz
4. 配置wsgi,並啓動python

# myweb_uwsgi.ini file
[uwsgi]nginx

# Django-related settingsweb

socket = :8000數據庫

# the base directory (full path)
chdir = /home/sites/blogprojectdjango

# Django s wsgi file
module = blogproject.wsgi服務器

# process-related settings
# master
master = trueapp

# maximum number of worker processes
processes = 4socket

# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
uwsgi --ini blogproject_uwsgi.ini post

5. 配置nginx代理真實服務器
nginx.conf /usr/local/nginx/conf/nginx/conf
server {
listen 8099;
server_name 127.0.0.1;
charset UTF-8;
access_log /var/log/nginx/myweb_access.log;
error_log /var/log/nginx/myweb_error.log;

client_max_body_size 75M;

location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_read_timeout 2;
}
location /static {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /home/sites/blogproject/static/; # 關聯項目靜態文件
}
}

nginx
nginx -s stop
nginx -s reload

pip freeze > requirements.txt # 記錄項目依賴
virtualenv --python=python3 env # 建立虛擬環境
source env/bin/activate
pip install -r requirements.txt # 安裝項目依賴
python manage.py collectstatic # 收集靜態文件 要在setting中配置STATIC_ROOT = os.path.join(BASE_DIR, 'static')
DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1', 'localhost ', '.zmrenwu.com']
python manage.py migrate #生成數據庫

https://www.cnblogs.com/frchen/p/5709533.htmlhttps://www.zmrenwu.com/post/20/

相關文章
相關標籤/搜索