1.申请腾讯云服务器https://console.cloud.tencent.com
1核2G新用户三年288RMB,一年95RMB。只能选一次,新用户福利。
腾讯云服务器系统选择Ubuntu。
2.登录云服务器,用户名默认为ubuntu,密码为你设置的密码。
sudo passwd root
su root
apt update
python --version
python3 --version
apt install python3-pip
pip3 install django
apt install mysql-server
apt install libmysqlclient-dev
apt install mysql-client
pip3 install mysqlclient
pip3 install uwsgi
manage.py
同级目录下新建uwsgi.ini
[uwsgi]
# Http通信方式的 IP地址:端口号(不使用nginx,可以通过浏览器直接访问)
# http = :7777
# 套接字方式的 IP地址:端口号(需要映射到nginx),此端口必须与后面的Nginx一致
socket = 127.0.0.1:6666
# 项目当前工作目录(绝对路径)
chdir = /yajun
# 项目中wsgi.py文件的目录,相对于当前工作目录
wsgi-file = zhangyajun_django/wsgi.py
# 进程个数
processes = 1
# 每个进程的线程个数
threads = 1
# 是否开启管理员进程,该进程用于管理其它进程,不与用户交互,如果需要,设为true
master = true
# 服务的pid记录文件
pidfile = /yajun/uwsgi.pid
# 服务的目志文件位置
daemonize = /yajun/uwsgi.log
# static-map = /yajun/static
# vacuum=true
apt install nginx
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
http {
server {
listen 8888;
server_name 81.68.109.233; #这里填你主机的公网IP
charset utf-8;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 20m; #允许客户端请求的最大单文件字节数
client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,
proxy_connect_timeout 1 ; #nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout 10; #后端服务器数据回传时间(代理发送超时)
proxy_read_timeout 10; #连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size 4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
proxy_buffers 4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size 64k; #高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
# 媒体文件目录(MP4,MP3等用户上传的数据,如果没有可以不写)
location /media {
alias /yajun/media; #你的media文件路径
}
# 静态文件目录(js,css等)
location /static {
alias /yajun/static; #你的static文件路径
}
# 项目文件路径
location / {
uwsgi_pass 127.0.0.1:6666; #这里与uwsgi一致
include /etc/nginx/uwsgi_params;
uwsgi_read_timeout 50;
# try_files $uri $uri/ =404; # 将这行注释掉
}
}
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
##
# Virtual Host Configs
##
#include /etc/nginx/conf.d/*.conf;
#include /etc/nginx/sites-enabled/*;
}
#mail {
# # See sample authentication script at:
# # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
#
# # auth_http localhost/auth.php;
# # pop3_capabilities "TOP" "USER";
# # imap_capabilities "IMAP4rev1" "UIDPLUS";
#
# server {
# listen localhost:110;
# protocol pop3;
# proxy on;
# }
#
# server {
# listen localhost:143;
# protocol imap;
# proxy on;
# }
#}
service nginx restart
netstat -ntlp 可以查看网络状态
uwsgi --ini uwsgi.ini
uwsgi --stop uwsgi.pid
uwsgi --ini uwsgi.ini