sqlite在nginx上安插django项目——–Gunicorn+Django+nginx+mysql

http://www.cnblogs.com/wt11/p/6420442.html

七、启动nginx

/app/nginx/sbin/nginx   启动nginx服务

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'

service iptatbles save

三、安装gunicorn

原先的博客我有写,那里就不写了

/EdmureBlog/dj.conf 

pip install gunicorn

在品种目录EdmureBlog下新建gunicorn的计划文件gunicorn.conf.py

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;

}

[root@localhost EdmureBlog]# pwd
/EdmureBlog

二、安装mysql

安装二进制mysql5.7http://blog.csdn.net/wb96a1007/article/details/51559741

自己用的mysql5.7 
64位的二进制包,官网下载安装编译好的二进制包,解压直接利用即可

若果要外表访问,则打开8000端口:

https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz

gunicorn.conf.py

六、运行gunicorn:

/sbin/iptables -I INPUT -p tcp –dport 8000 -j ACCEPT

[root@localhost EdmureBlog]# nohup   /usr/local/bin/gunicorn  
EdmureBlog.wsgi:application   -c   /EdmureBlog/gunicorn.conf.py  &

五、同时,django项目的站点名(www.wt.com)加入到 settings.py的ALLOWED_HOSTS里。

[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

[root@localhost EdmureBlog]# pwd
/EdmureBlog

一、安装nginx

 /app/nginx/sbin/nginx -t 检查安排语法是不是正确

八、关闭防火墙,没有dns的话,Windows修改hosts文件,浏览器访问www.wt.com即可 

四、在EdmureBlog下新建nginx的布署文件dj.conf ,将其链接到/app/nginx/conf/extra下      ln -s
/EdmureBlog/dj.conf   /app/nginx/conf/extra/dj.conf

ALLOWED_HOSTS = [‘www.wt.com’,]

nginx主配置文件/app/nginx/conf/nginx.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;
     }

}
网站地图xml地图