远程安装依赖:以来文件名relyon.txt(自取),文件内容:
Django==1.11.7
django-redis==4.9.0
itsdangerous==0.24
MarkupSafe==1.0
Pillow==5.1.0
PyMySQL==0.8.1
pytz==2018.4
Werkzeug==0.14.1
安装uwsgi:pip install uwsgi
编写uwsgi.ini文件,将其放在与文件manage.py同一个目录下:
************************************************************
[uwsgi]# 使用nginx连接时 使用
socket=0.0.0.0:8000
# 直接作为web服务器使用
#http=127.0.0.1:8010
# 配置工程目录
chdir=/root/code/project/Django_project
# 配置项目的wsgi目录。相对于工程目录
wsgi-file=Django_project/wsgi.py
virtualenv =/root/code/venv/.blogvenv
#配置进程,线程信息
processes=1
threads=1
enable-threads=True
master=True
pidfile=uwsgi.pid
daemonize=uwsgi.log
************************************************************
安装Nginx:如果Nginx原先安装过,最好先彻底删除再重新安装(彻底删除查看 https://blog.csdn.net/u010571844/article/details/50819704)
#apt-get update
#apt install nginx
启动Nginx:
#/etc/init.d/nginx start #启动
/etc/init.d/nginx stop #关闭
/etc/init.d/nginx restart #重启
Nginx默认监听80端口
所以安装完毕,访问localhost或者服务器自己的ip地址就ok了。
编写nginx.conf文件,放在/etc/nginx里。文件内容如下:
#user www-data;
#user nginx;
user root;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
http {
##
# 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_disable "msie6";
# 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/*;
#server{
#listen 80;
#server_name 39.108.89.249;
#server_name www.sirouyang.xyz;
#root /apps/www;
#location /fresh{
# alias /apps/www/fresh;
# index index.html;
#}
#}
server {
# 监听在80端口
listen 80;
# 主机地址
server_name 106.12.5.252;
# 如果有域名,可以使用域名代替主机地址
# server_name www.blog.com blog.com;
# 访问路由就是主机地址时,
location / {
#root /apps/www/MyBlog;
#index app/templates/main/index.html;
# 反向代理监听在127.0.0.1:8000位置的uwsgi服务器
# 前提是uwsgi已经运行并监听在8000端口
include uwsgi_params;
uwsgi_pass 0.0.0.0:8000;
}
# 访问路由就是主机地址时
# location /blog {
#root /apps/www/MyBlog;
#index app/templates/main/index.html;
# 反向代理监听在127.0.0.1:5001位置的uwsgi服务器
# 前提是uwsgi已经运行并监听在8000端口
# include uwsgi_params;
# uwsgi_pass 127.0.0.1:5001;
# }
# 访问静态资源
location /static {
#root html/blog;
# 静态资源目录
alias /root/code/project/Django_project;
}
# 访问指定文件夹下的任意资源
# location /fresh{
# alias /code/Django_project/fresh;
# # 默认访问某个页面
# index index.html;
# }
# location /2048{
# alias /apps/www/2048;
# index index.html;
# }
}
}
#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;
# }
#}
安装mysql:
#apt install mysql-server
#apt install mysql-client
#apt install libmysqlclient-dev
mysql -r -p 验证是否启动mysql服务
运行:找到uwsgi.ini虽在位置(manage.py同级目录)运行:
#ps -ef | grep uwsgi
#ls
#kill -9 杀死uwsgi主进程
#uwsgi --ini uwsgi.ini即可