最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

Docker搭建WEB環(huán)境之 Nginx & uWSGI

2023-06-06 08:14 作者:魔都碼農(nóng)  | 我要投稿


第一步安裝Docker

PS:主機如果已經(jīng)安裝Docker,《第一步安裝Docker》可跳過。

1.更新Ubuntu的apt源

sudo apt-get update

2.安裝包允許apt通過HTTPS使用倉庫

sudo dpkg --configure -a sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

3.添加Docker官方GPG key

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

4.設(shè)置Docker穩(wěn)定版?zhèn)}庫

sudo add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

  • [arch=arm64] 注意系統(tǒng)的平臺選擇

5.更新apt源

sudo apt-get update

6.安裝最新版本Docekr CE(社區(qū)版)

sudo apt-get install docker-ce

7.查看安裝Docker的版本

docker --version

8.檢查Docker CE是否安裝正確

sudo docker run hello-world

9.更新為國內(nèi)源

sudo vim /etc/docker/daemon.json

寫入以下文本

{ ? ? ? ?"registry-mirrors": [ ? ? ? ? ? ? ? ?"https://registry.docker-cn.com", ? ? ? ? ? ? ? ?"https://hub-mirror.c.163.com/" ? ? ? ?] }

10.重啟docker

sudo systemctl restart docker

第二步新建容器web-v1,鏡像centos8.4.2105

1.新建docker容器web-v1

sudo docker run -d -it -p 80:80 -p 8000:8000 --name web-v1 centos:8.4.2105

2.進(jìn)入docker容器

sudo docker exec -it web-v1 bash

3.安裝 yum-utils 工具

yum install yum-utils

出現(xiàn)錯誤:

執(zhí)行以下操作

cd /etc/yum.repos.d/ sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-* sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*

  • 重新安裝

yum install yum-utils

第二步安裝 Nginx

vi /etc/yum.repos.d/nginx.repo

寫入文本

[nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true

安裝Nginx

yum install nginx

啟動Nginx

nginx

訪問http://192.168.157.129/


第三步安裝Python虛擬環(huán)境

1.安裝依賴

yum install -y gcc automake autoconf libtool make libffi-devel yum install -y gcc gcc-c++ yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel xz-devel yum install -y patch yum install -y git wget unzip

2.安裝pyenv

mkdir ~/.pyenv //git下載 git clone git://github.com/pyenv/pyenv.git ~/.pyenv //本地下載 wget -P ?~/.pyenv http://192.168.157.1/Share/pyenv-master.zip unzip ?~/.pyenv/pyenv-master.zip -d ?~/.pyenv mv ~/.pyenv/pyenv-master/* ~/.pyenv/ cd ~/.pyenv && src/configure && make -C src echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc ? echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc ? echo 'eval "$(pyenv init -)"' >> ~/.bashrc ? exec $SHELL -l

3.安裝pyenv virtualenv

//git下載 git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv //本地下載 wget -P ?$(pyenv root)/plugins/pyenv-virtualenv http://192.168.157.1/Share/pyenv-virtualenv-master.zip unzip ?~/.pyenv/plugins/pyenv-virtualenv/pyenv-virtualenv-master.zip -d ?~/.pyenv/plugins/pyenv-virtualenv mv ~/.pyenv/plugins/pyenv-virtualenv/pyenv-virtualenv-master/* ~/.pyenv/plugins/pyenv-virtualenv/ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile exec "$SHELL"

4.創(chuàng)建虛擬環(huán)境

// 下載并安裝python3.11.3 v=3.11.3;wget https://npm.taobao.org/mirrors/python/$v/Python-$v.tar.xz -P ~/.pyenv/cache/;pyenv install $v ?// 查看pyenv版本 pyenv versions //新建test環(huán)境 pyenv virtualenv 3.11.3 test pyenv activate test pyenv deactivate test

5.虛擬環(huán)境test中安裝Django

安裝Django

pyenv activate test pip install django python -m django --version /root/.pyenv/versions/test/bin/pip list

第四步Django創(chuàng)建項目

創(chuàng)建項目

cd /usr/share/nginx/html django-admin startproject mysite

在setting.py里面需要添加ALLOWED_HOSTS=["*"]

vi /usr/share/nginx/html/mysite/mysite/settings.py

啟動項目

python manage.py runserver 0.0.0.0:8000

報錯

提示執(zhí)行?python manage.py migrate


重啟系統(tǒng),訪問http://192.168.157.129:8000/

python manage.py runserver 0.0.0.0:8000


第五步安裝uwsgi

pyenv activate test pip install uwsgi //使用douban源安裝 pip install uwsgi -i https://pypi.douban.com/simple/

配置uwsgi.ini文件

cd /usr/share/nginx/html/mysite/mysite vi ?/usr/share/nginx/html/mysite/mysite/uwsgi.ini#添加配置選擇 [uwsgi] #配置和nginx連接的socket連接 socket = 127.0.0.1:8000 #配置項目路徑,項目的所在目錄 chdir = /usr/share/nginx/html/mysite #配置wsgi接口模塊文件路徑 wsgi-file = mysite/wsgi.py #配置啟動的進(jìn)程數(shù) #配置啟動管理主進(jìn)程 master = True #配置存放主進(jìn)程的進(jìn)程號文件 pidfile =/usr/share/nginx/html/mysite/uwsgi.pid #配置dump日志記錄 daemonize = /var/log/mysite_uwsgi.log # 指定python 環(huán)境 home = /root/.pyenv/versions/test/ post-buffering = 65536 max-requests = 10000 vacuum = true #自動更新 #touch-reload = /usr/share/nginx/html/mysite/.git/index

后臺啟動uwsgi

/root/.pyenv/versions/test/bin/uwsgi -d -i /usr/share/nginx/html/mysite/mysite/uwsgi.ini

配置Nginx

cd /etc/nginx/conf.d/ vi /etc/nginx/conf.d/test.confserver { ?listen ? ? ? 80; ?server_name ?192.168.157.129; ?location / { ? ? ? ?#add_header 'Access-Control-Allow-Origin' '*'; ? ? ? ?include ? ? ?/etc/nginx/uwsgi_params; ? ? ? ?uwsgi_pass ? 127.0.0.1:8000; ? ? ? ?uwsgi_param UWSGI_PYHOME /root/.pyenv/versions/test/bin/python; # 指向虛擬環(huán)境目錄 ? ? ? ?uwsgi_param UWSGI_MAX_TEMP_FILE_SIZE ?1000m; ? ? ? ?uwsgi_param UWSGI_MAX_TEMP_WRITE_SIZE ?1000m; ? ? ? ?uwsgi_param UWSGI_SCRIPT app:app; # 指定啟動程序 ?} ?location /static/ { ? ?root /usr/share/nginx/html/mysite/mysite; ? ?break; ?} }

重啟Nginx

nginx -s reload

訪問:http://192.168.157.129/



Docker搭建WEB環(huán)境之 Nginx & uWSGI的評論 (共 條)

分享到微博請遵守國家法律
汨罗市| 东丰县| 增城市| 莱芜市| 屏东县| 蛟河市| 贵溪市| 新化县| 大城县| 通州市| 崇礼县| 江陵县| 东源县| 繁峙县| 东阳市| 庄浪县| 彭水| 大方县| 中西区| 彭山县| 安福县| 阜南县| 苗栗市| 利津县| 泸州市| 沁阳市| 新宾| 恩施市| 法库县| 昔阳县| 甘孜县| 武功县| 博野县| 叙永县| 昌宁县| 巴彦县| 莲花县| 田东县| 永靖县| 察哈| 弥渡县|