服务器配置是Ubuntu14.04 64位OS

ubuntu14.04默认是安装好了python2.7版本不用自己安装了。

先更新下源

sudo apt-get update

第一步先安装pip

sudo apt-get install -y python-pip

有些时候安装pip前需要安装几个相关包

sudo apt-get install -y python-dev

sudo apt-get install -y libevent-dev

安装完pip后我们开始安装django

sudo pip install Django==1.7.1

安装后输入Python进入交互环境输入django.VERSION查看版本

开始装uwsgi

下面这几个可能是相关包

sudo apt-get install -y build-essential

sudo apt-get install -y zliblg-dev

sudo apt-get install -y libsqlite3-dev

sudo apt-get install -y libreadline6-dev

sudo apt-get install -y libgdbm-dev

sudo apt-get install -y libbz2-dev

sudo apt-get install -y tk-dev

sudo apt-get install -y uwsgi-plugin-python

安装uwsgi

sudo pip install uwsgi

可以写个test.py

# test.py
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return [b"Hello World"] # python3
#return ["Hello World"] # python2

输入uwsgi --http :8000 --wsgi-file test.py

浏览器输入http://example.com:8000看是否显示helloworld

再安装git

sudo apt-get install -y git

克隆项目

用uwsgi启动项目

uwsgi --ini ${current_path}${sep}/$uwsgi_name

安装nginx

sudo apt-get install -y nginx

修改nginx配置文件,删掉原先包里的东西,加上软链接

ln -s ${current_path}${sep}${p_name}${sep}${conf_name} /etc/nginx/sites-enabled/

(

sudo ln -s /data/www/ts/conf/ts_nginx.conf /etc/nginx/sites-enabled/
sudo ln -s /data/www/ts/conf/ts_nginx.conf /etc/nginx/sites-available/

)

service nginx restart

输入网址就可以了。

另外你需要

python manage.py collectstatic

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATIC_ROOT = os.path.join(BASE_DIR, 'static2', ).replace('\\', '/')
STATIC_URL = '/static/'
然后将静态文件从static2移动到static目录下

输入网址就可以了。

几个配置文件:

nginx.conf:

# the upstream component nginx needs to connect to
upstream django {
server unix:/etc/nginx/django/daowang/Wangdao.sock; # for a file socket
} # configuration of the server
server {
# the port your site will be served on
listen 80;
# the domain name it will serve for
server_name http://114.215.157.15/; # substitute your machine's IP address or FQDN
charset utf-8; # max upload size
client_max_body_size 75M; # adjust to taste # Django media
location /media {
alias /etc/nginx/django/daowang/static/media; # your Django project's media files - amend as required
} location /static {
alias /etc/nginx/django/daowang/static; # your Django project's static files - amend as required
} location /FingerHire{
proxy_pass http://127.0.0.1:8080;
} # Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /etc/nginx/django/daowang/uwsgi_params; # the uwsgi_params file you installed
}
}

uwsgi.ini

[uwsgi]

# Django-related settings
# the base directory (full path)
chdir = /etc/nginx/django/daowang
# Django's wsgi file
module = Wangdao.wsgi
# master
master = true
# maximum number of worker processes
processes = 32
max-requests = 1000
# the socket (use the full path to be safe
socket = /etc/nginx/django/daowang/Wangdao.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
#chown-socket = www-data:www-data
# clear environment on exit
vacuum = true
daemonize = /var/log/uwsgi/Wangdao.log
pidfile = /tmp/project-master.pid
# added 2014-09-17
reload-on-as = 126
reload-on-rss = 126
enable-threads = true
pythonpath = /etc/nginx/django/daowang

uwsgi_params

uwsgi_param  QUERY_STRING       $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length; uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param HTTPS $https if_not_empty; uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;

配置下根目录下的wsgi.py

import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Wangdao.settings") from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

常用命令:

1.查看端口占用情况:

netstat -lpnt

2.杀死所有uwsgi进程

killall -9 uwsgi

3.uwsgi启动命令

uwsgi --ini /etc/nginx/django/lovep2c/lovep2c_uwsgi.ini

4.关闭uwsgi命令

uwsgi --stop /tmp/project-master.pid

5.重启uwsgi命令

uwsgi --reload /tmp/project-master.pid

nginx错误日志:

tail /var/log/nginx/error.log

uwsgi日志:

tail /var/log/uwsgi/lovep2c.log

项目错误日志:

tail /etc/nginx/django/debug.log

tail /etc/nginx/django/error.log

参考网址:https://uwsgi.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

												

ubuntu下配置nginx+uwsgi+django的更多相关文章

  1. virtualenv下配置nginx uwsgi Django

    1.安装virtualenv,创建虚拟环境django15 sudo apt-get install virtualenv virtualenv env source bin/active pip i ...

  2. Ubuntu下配置Nginx HTTPS

    HTTPS(全称:Hypertext Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全版.即HTTP下加入S ...

  3. Ubuntu下使用Nginx+uWSGI+Flask(初体验)

    Ubuntu 18.04,Nginx 1.14.0, uWSGI 2.0.17.1,Flask, 前言 Windows不支持uWSGI!为了上线自己的项目,只能选择Linux. 自己前面开发了一个Fl ...

  4. flask部署:Ubuntu下使用nginx+uwsgi+supervisor部署flask应用

    之前一直用的Centos或者Red hat,自从使用Ubuntu后,发现Ubuntu使用起来更方便,自此爱上Ubuntu. 一.从github上下载flask应用 1.我已经成功将自己编写好的应用上传 ...

  5. Ubuntu下配置Nginx+PHP

    1.安装Nginxapt-get install nginx 2.启动Nginxservice nginx start 3.访问服务器IP 如果看到“Welcome to nginx!”说明安装好了. ...

  6. 阿里云云服务器ubuntu配置nginx+uwsgi+django记录文档

    1 安装ssh 1  sudo apt-get update 2  sudo apt-get install openssh-server 3  sudo ps -e |grep ssh  有sshd ...

  7. ubuntu下配置Apache+mod_wsgi+Django项目(个人测试)

    经过了一个星期的摸索,查找资料以及实验,我搭建的环境基本能用(还有就是Django后台的静态文件加载的问题) 这里面只是介绍一下我的过程,因为对应Apache还不是很熟练,特别是配置文件.只能供大家参 ...

  8. 阿里云上,Ubuntu下配置Nginx,在tomcat中加了https协议就不可以了

    问题 阿里云上,Ubuntu服务器,本来部署的是tomcat,并且使用了https 协议.后来为了静态资源分离集成了 nginx,nginx代理跳转到 tomcat.刚开始直接访问http 网址发现, ...

  9. Ubuntu Nginx uwsgi django 初试

    /************************************************************************************** * Ubuntu Ngi ...

随机推荐

  1. 【每周一译】愚蠢的指标:Java中使用最多的关键字

    此翻译纯属个人爱好,由于水平所限,翻译质量可能较低.网络上可能存在其它翻译版本,原文地址:http://blog.jooq.org/2013/08/26/silly-metrics-the-most- ...

  2. Android 类似未读短信图标显示数字效果的分析

    之前一直以为是应用本身在对图标进行修改,看了源码之后发现其实主要的工作并不是应用自己完成的,主要的工作在是launcher里面完成的. 关于系统里面类似未读短信的具体处理流程如下, 原理 一个应用要实 ...

  3. SQL Server索引进阶:第三级,聚集索引

    原文地址: Stairway to SQL Server Indexes: Level 3, Clustered Indexes 本文是SQL Server索引进阶系列(Stairway to SQL ...

  4. ASP.NET -- repeater控件的使用

    转载自网络-原网址[http://blog.csdn.net/haitaodoit/article/details/7021214] repeater绑定数据: protected void Page ...

  5. iOS合并静态库文件

    具体命令如下(在控制台输入如下命令): lipo -create 其中一个要合并的静态库 另一个要合并的静态库 -output 合并后的静态库

  6. 5.7.1.2 eval() 方法

    现在我们介绍最后一个方法,这大概是ECMAScript语言中最强大的一个方法:eval().eval()方法就想一个完整的ECMAScript解析器,它只接受一个参数,即要执行的ECMAScript( ...

  7. linxu添加定时任务

    1. 在需要定时执行的php文件的第一行加 也就是文件开头加  #! /bin/local/php -q 其中 /bin/local/php 是自己的php.exe 所在的位置 2. 上传要定时执行的 ...

  8. 图中两点间路径为l的数目

    用矩阵G表示图的邻接阵. G2中的元素就是两点间路径为2的路径数,同理G3就是两点间路径为3的路径数目. 并且此结论同样适用于有向图. 甚至,此结论适用于有权图,只是算出来的不再是路径数,而是各条路径 ...

  9. document.compatMode简介

    对于document.compatMode,很多朋友可能很少接触,知道他的存在却不清楚他的用途.今天在ext中看到 document.compatMode的使用,感觉这个对于我们开发兼容性的web页面 ...

  10. 在windows下配置对github的操作--基本操作

    一.下载安装 git for widows软件 git for widows 是专门用来在windows下操作 github的软件,提供bash(命令行) 和 gui两种方式. 在bash下,其实就是 ...