在nginx上部署django项目--------Gunicorn+Django+nginx+mysql
一、安装nginx
以前的博客我有写,这里就不写了
http://www.cnblogs.com/wt11/p/6420442.html
二、安装mysql
我用的mysql5.7 64位的二进制包,官网下载安装编译好的二进制包,解压直接使用即可
https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
安装二进制mysql5.7http://blog.csdn.net/wb96a1007/article/details/51559741
三、安装gunicorn
pip install gunicorn
在项目目录EdmureBlog下新建gunicorn的配置文件gunicorn.conf.py
[root@localhost EdmureBlog]# pwd
/EdmureBlog
[root@localhost EdmureBlog]# ls
backend db.sqlite3 gunicorn.conf.py manage.py nginx.conf repository static utils
blogss debug.log EdmureBlog gunicorn.error.log Monaco.ttf __pycache__ singleton.py templates web
gunicorn.conf.py
import multiprocessing bind = "127.0.0.1:8080"
workers = 2 #workers是工作线程数,一般设置成:服务器CPU个数 + 1
errorlog = '/EdmureBlog/gunicorn.error.log'
#accesslog = './gunicorn.access.log'
#loglevel = 'debug'
proc_name = 'gunicorn_blog_project'
四、在EdmureBlog下新建nginx的配置文件dj.conf ,将其链接到/app/nginx/conf/extra下 ln -s /EdmureBlog/dj.conf /app/nginx/conf/extra/dj.conf
/EdmureBlog/dj.conf
server {
listen 8000;
server_name www.wt.com; #访问django项目的网站
access_log /EdmureBlog/logss/nginx.access.log;#访问日志
error_log //EdmureBlog/logss//nginx.error.log;#错误日志
location / {
proxy_pass http://127.0.0.1:8080;#动态请求交给gunicorn,8080端口就是gunicorn用的端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /robots.txt {
alias /EdmureBlog/logss/static/robots.txt;
}
location /favicon.ico {
alias /EdmureBlog/logss/static/img/favicon.ico;
}
location ~ ^/(media|static)/ { # 注意这个static,如果项目中静态文件的存放目录是 /项目/statics,那么这里也要写成media|statics,然后在html文件中引用css和js的时候,路径也要写成/statics/css/...
root /EdmureBlog/; #静态文件存放路径
expires 30d;
}
# this prevents hidden files (beginning with a period) from being served
location ~ /\. {
access_log off; log_not_found off; deny all;
}
}
nginx主配置文件/app/nginx/conf/nginx.conf
user root;
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;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
include extra/dj.conf; #django站点
include extra/www.conf; # 其他站点
include extra/bbs.conf; #其他站点
include extra/status.conf;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; }
五、同时,django项目的站点名(www.wt.com)加入到 settings.py的ALLOWED_HOSTS里。
ALLOWED_HOSTS = ['www.wt.com',]
如果要外部访问,则打开8000端口:
/sbin/iptables -I INPUT -p tcp --dport 8000 -j ACCEPT
service iptatbles save
六、运行gunicorn:
[root@localhost EdmureBlog]# pwd
/EdmureBlog
[root@localhost EdmureBlog]# nohup /usr/local/bin/gunicorn EdmureBlog.wsgi:application -c /EdmureBlog/gunicorn.conf.py &
七、启动nginx
/app/nginx/sbin/nginx -t 检查配置语法是否正确
/app/nginx/sbin/nginx 启动nginx服务
八、关闭防火墙,没有dns的话,Windows修改hosts文件,浏览器访问www.wt.com即可
在nginx上部署django项目--------Gunicorn+Django+nginx+mysql的更多相关文章
- 在nginx上部署vue项目(history模式);
在nginx上部署vue项目(history模式): vue-router 默认是hash模式,使用url的hash来模拟一个完整的url,当url改变的时候,页面不会重新加载.但是如果我们不想has ...
- 在nginx上部署vue项目(history模式)--demo实列;
在很早之前,我写了一篇 关于 在nginx上部署vue项目(history模式) 但是讲的都是理论,所以今天做个demo来实战下.有必要让大家更好的理解,我发现搜索这类似的问题还是挺多的,因此在写一篇 ...
- centos上部署flask项目之环境配置-MySQL的安装
1.添加mysql 的yum源 wget 'https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm' rpm ...
- 在Nginx上部署ThinkPHP,解决Pathinfo问题
在Nginx上部署ThinkPHP,解决Pathinfo问题 事实上.要解决nginx不支持pathinfo的问题.有两个解决思路,一是不使用pathinfo模式,二是改动nginx的配置文件,使它支 ...
- Django项目和Django初体验和创建、目录结构认识
.MVC的设计方式(跟Flask一样,都是MVC的设计模式) .开发效率高 .功能强大(丰富的第三方组件) .安全性高(帮助开发者规避安全漏洞) 目前市面上使用:Django>Flask #使用 ...
- nginx上部署python web
nginx上部署python web http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
- Nginx上部署HTTPS
Nginx上部署HTTPS依赖OpenSSL库和包含文件,即须先安装好libssl-dev,且ln -s /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/, ...
- 在Linux上部署Web项目
You believe it or not there is a feeling, lifetime all not lost to time. 在Linux上部署Web项目 这个是普通的web项目, ...
- Nginx上部署HTTPS + HTTP2
Nginx上部署HTTPS依赖OpenSSL库和包含文件,即须先安装好libssl-dev(或者OpenSSL),且ln -s /usr/lib/x86_64-linux-gnu/libssl.so ...
随机推荐
- 【AGC013D】Pilling Up dp
Description 红蓝球各无限多个. 初始时随意地从中选择 n 个, 扔入箱子 初始有一个空的序列 接下来依次做 m 组操作, 每组操作为依次执行下述三个步骤 (1) 从箱子中取出一个求插入序列 ...
- 八大排序算法的python实现(七)基数排序
代码: #coding:utf-8 #author:徐卜灵 import math #print math.ceil(3.2) 向上取整4.0 #print math.floor(3.2) 向下取整3 ...
- IOS中NSUserDefaults的用法
NSUserDefaults适合存储轻量级本地数据,比如要保存用户登陆的用户名.密码,使用NSUserDefaults是首选.下次再登陆的时候就可以直接从NSUserDefaults里面读取上次登陆的 ...
- SqlBulkCopy使用注意事项
1. 有标识列的表 1.1 SqlBulkCopyOptions.KeepIdentity 必须设置!否则会出现复制过去的数据产生标识列发现变化的情况! 1.2 如果原表的标识列即为主键, 那按1. ...
- there is already 'RtController' bean method 项目报错
今天开发项目时候发现项目报错启动的时候,也没有具体指的是哪一行报错,其实很简单的知道,首先看下报错信息: there is already 'RtController' bean method pub ...
- EA添加时序图
在项目浏览器的空白处右击 http://blog.csdn.net/craftsman1970/article/details/70877530 不同于大部分面向对象或者UML的书籍,在讨论完类图/对 ...
- 使用Swagger生成简单接口文档
使用swagger通过简单的配置可以生成简单的接口文档: 依赖包: // Swagger2 compile 'io.springfox:springfox-swagger2:2.8.0' compil ...
- tornado 09 cookie和session
tornado 09 cookie和session 一.cookie #有什么办法能够让浏览器记住登录信息,下次再打开的时候可以自动登录?网站是如何记录登录信息的? class SetCookieHa ...
- samtools软件作用
samtools的说明文档:http://samtools.sourceforge.net/samtools.shtml samtools是一个用于操作sam和bam文件的工具合集,包含有许多命令.以 ...
- Apache Shiro(六)-基于URL配置权限
数据库 先准备数据库啦. DROP DATABASE IF EXISTS shiro; CREATE DATABASE shiro DEFAULT CHARACTER SET utf8; USE sh ...