首页 > IT职业 > IT生活 > 阿里云 部署django全攻略
useradd -m zhaozhao
zhaozhao)添加密码(默认创建的用户没有密码)passwd zhaozhao
usermod -a -G adm zhaozhao usermod -a -G sudo zhaozhao
exitssh zhaozhao@主机ip地址
mkdir ~/data
mkdir ~/data/{backup,code,logs,server,soft,virtual}
支持中文
sudo locale-gen zh_CN.UTF-8
sudo apt install python3
ssh-keygen -t rsa # 生成加密算法为 rsa的秘钥ssh-copy-id zhaozhao@远程ip #将公钥拷贝到服务器端(公钥可多次使用,私钥相当于一卡通!)
~/data/code
tar -zcvf fangyuanxiaozhan.tar.gz fangyuanxiaozhan
scp fangyuanxiaozhan.tar.gz zhaozhao@远程ip:~/data/code/fangyuanxiaozhan.tar.gz
pip freeze > requirements.txt
scp requirements.txt zhaozhao@远程ip:~/data/soft/requirements.txt
sudo apt install python-pip sudo pip install virtualenv sudo pip install virtualenvwrapper
virtualenvwrapper.sh
# 添加pytho虚拟环境配置vim ~/.bashrcexport WORKON_HOME=$HOME/.virtualenvssource /usr/local/bin/virtualenvwrapper.sh
# 创建虚拟环境mkvirtualenv dj_py3 --python="/usr/bin/python3"# 安装依赖包pip install -r ~/data/soft/requirements.txt
出现错误:Python.h: No such file or directory
解决方式:sudo apt-get install python3-dev
scp nginx-1.10.3.tar.gz zhaozhao@远程ip:~/data/soft/nginx-1.10.3.tar.gz scp openssl-1.0.2l.tar.gz zhaozhao@远程ip:~/data/soft/openssl-1.0.2l.tar.gz scp zlib-1.2.11.tar.gz zhaozhao@远程ip:~/data/soft/zlib-1.2.11.tar.gz
sudo apt-get install libpcre3 libpcre3-dev
tar -zxvf zlib-1.2.11.tar.gzcd zlib-1.2.11 ./configure make sudo make installcd ..
~/data/soft/openssl-1.0.2l)tar -zxvf openssl-1.0.2l.tar.gz
# 解压nginxtar -zxvf nginx-1.10.3.tar.gz# 进入nginx安装目录cd nginx-1.10.3# 在指定位置安装nginx./configure --prefix=/opt/nginx/ --with-openssl=~/data/soft/openssl-1.0.2l# 编译make# 安装sudo make install# 启动cd /opt/nginx/sbin sudo ./nginx# 查看ps ajx | grep nginx
sudo apt-get install mysql-server
在项目目录的同名模块下,新建配置文件
uwsgi.ini
uwsgi.ini
2.在配置文件中加入以下内容
[uwsgi]# 配置nginxsocket = 127.0.0.1:3309# 配置项目目录chdir = /home/zhaozhao/data/code/fangyuanxiaozhan# 配置入口模块wsgi-file = fangyuanxiaozhan/wsgi.py# 开启master, 将会多开一个管理进程, 管理其他服务进程master = True# 服务器开启的进程数量processes = 2# 服务器进程开启的线程数量threads = 4# 以守护进程方式提供服, 输出信息将会打印到log中# daemonize = wsgi.log# 退出的时候清空环境变量vacuum = true# 进程pidpidfile=uwsgi.pid
3.以配置好的文件 uwsgi.ini启动uwsgi
uwsgi --ini uwsgi.ini

nginx.conf
nginx.conf配置内容
#user nobody;worker_processes 1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events {
worker_connections 1024;
}
http { include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on; #tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; #gzip on;
server {
listen 80;
server_name localhost; #charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm;
#}
location / { # 将nginx所有请求转到uwsgi
include uwsgi_params; # uwsgi的ip与端口
uwsgi_pass 127.0.0.1:3309;
}
location /static {
alias /home/zhaozhao/data/code/fangyuanxiaozhan/static;
} #error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ .php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ .php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}}
2.重启
nginx
cd /opt/nginx/sbin sudo ./nginx -s stop sudo ./nginx
ps ajx | grep uwsgikill -9 2844
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/3566/viewspace-2803950/ ,如需转载,请注明出处,否则将追究法律责任。