在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 ...
随机推荐
- ecliplse里tomcat正常启动后http://localhost:8080/报错404
如下图所示,新建一个工作区间,添加tomcat之后通过ecliplse启动tomcat之后: 访问http://localhost:8080/出现404: 解决方法: 1.确保tomcat里面所有项目 ...
- Unity性能优化专题---腾讯牛人分享经验
这里从三个纬度来分享下内存的优化经验:代码层面.贴图层面.框架设计层面. 一.代码层面. 1.foreach. Mono下的foreach使用需谨慎.频繁调用容易触及堆上限,导致GC过早触发,出现卡顿 ...
- CH收藏的书
论语 道德经 墨子
- select chosen 的入门使用
首先要引用 因为肯定要引用jq,所以就没有写啦 <link rel="stylesheet" href="__ROOT__/Public/jschy/chosen_ ...
- linux centos 宝塔主机控制面板安装和安全狗安装过程记录
linux 宝塔控制面板 安装过程yum install -y wget && wget -O install.sh http://103.224.251.79:5880/instal ...
- 单机,伪分布式,完全分布式-----搭建Hadoop大数据平台
Hadoop大数据——随着计算机技术的发展,互联网的普及,信息的积累已经到了一个非常庞大的地步,信息的增长也在不断的加快.信息更是爆炸性增长,收集,检索,统计这些信息越发困难,必须使用新的技术来解决这 ...
- MyBatis配置文件的配置说明
Properties 1.创建一个资源文件jdbc.properties: jdbc.driverClassName=oracle.jdbc.driver.OracleDriver jdbc.url= ...
- (Keil) Debug & Simulation 操作
0x00 printf在MCU環境下print debug error message,利用Logic Analyzer模擬MCU register or GPIO狀態. 若是要要使用printf函數 ...
- Qt 学习之路 2(43):QStringListModel
Qt 学习之路 2(43):QStringListModel 豆子 2013年2月13日 Qt 学习之路 2 38条评论 上一章我们已经了解到有关 list.table 和 tree 三个最常用的视图 ...
- jenkins-APP打包页面展示二维码【转】
背景: 客户要求在APP打包页面展示二维码.虽然感觉这个功能很鸡肋,但是还是加上吧. 效果展示: 配置: 在上图中,106对应的内容是BuildName,我们可以通过build-name-setter ...