uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。
WSGI / uwsgi / uWSGI 三者区别:
WSGI是一种通信协议,Flask,webpy,Django、CherryPy等等都自带WSGI,不过性能都不好。
uwsgi同WSGI一样是一种通信协议。
uWSGI是实现了uwsgi和WSGI两种协议的Web服务器。
自己配置
uwsgi.ini
# mysite_uwsgi.ini file
[uwsgi]
chdir = /home/log_collect_statistics
module= log_collect_statistics.wsgi:application
home = /opt/python
buffer-size = 65536
master = true
processes = 4
socket = :8080
#http= 192.168.8.192:8081
#http-socket = 192.168.8.192:8081
#http://60.205.211.11 172.17.36.8
#http-socket = 172.17.36.8:8081
enable-threads = true
vacuum = true
pidfile=uwsgi.pid
daemonize=logs/uwsgi.log
log-maxsize = 50000000
disable-logging = true
nginx.conf
upstream django {
server 127.0.0.1:8080; # 8081
}
server {
listen 18000;
server\_name localhost;
#charset koi8-r;
charset utf-8;
access\_log logs/django.access.log main;
location / {
#root html;
#index index.html index.htm;
include uwsgi\_params;
uwsgi\_pass django;
uwsgi\_read\_timeout 2;
}
location /static/{
alias /home/log\_collect\_statistics/all\_static;
expires 30d;
autoindex on;
}
#error\_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error\_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
settings.py
"""
Django settings for log_collect_statistics project.
Generated by 'django-admin startproject' using Django 2.1.15.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_KEY = '--1k(694cyc_6s7r=7!hp25km_2*hp^j$b&hm(3%+ydq68_se4'
DEBUG = False
ALLOWED_HOSTS = ["*"]
INSTALLED_APPS = [
'django.contrib.admin', # 内置后台管理系统
'django.contrib.auth', # 内置用户认证系统
'django.contrib.contenttypes', # 记录项目中所有的model元数组(Django 的 ORM框架)
'django.contrib.sessions', # session会话功能, 用于标识当前访问网站用户身份,记录像相关用户信息
'django.contrib.messages', # 消息提示功能
'django.contrib.staticfiles', # 查询静态资源路径
'app.apps.AppConfig',
'user.apps.UserConfig',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware', # 内置的安全机制,保护用户与网站的通信安全
'django.contrib.sessions.middleware.SessionMiddleware', # 会话session功能
'django.middleware.locale.LocaleMiddleware', # 使用中文
'django.middleware.common.CommonMiddleware', # 处理请求信息,规范化请求内容
'django.middleware.csrf.CsrfViewMiddleware', # 开启CSRF防护功能
'django.contrib.auth.middleware.AuthenticationMiddleware', # 开启内置的用户认证系统
'django.contrib.messages.middleware.MessageMiddleware', # 开启内置的信息提示功能
'django.middleware.clickjacking.XFrameOptionsMiddleware', # 防止恶意程序点击劫持
'log_collect_statistics.middlewares.cors.Mymiddle',
'log_collect_statistics.middlewares.ExceptionLoggingMiddleware.ExceptionLoggingMiddleware',
]
ROOT_URLCONF = 'log_collect_statistics.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates', # 定义模板引擎,用于识别模板里面的变量和指令
'DIRS': [os.path.join(BASE_DIR, 'templates'), ], # 设置模板所在路径
'APP_DIRS': True, # 是否在APP里面查找模板文件
'OPTIONS': { # 用于填充在RequestContext中上下文的调用函数,一般情况不做任何修改
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'log_collect_statistics.wsgi.application'
if DEBUG:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # 链接数据库的类型
'NAME': 'log_collect', # 链接数据库的名字
'HOST': '192.168.10.5', # 数据库主机地址
'PORT': 3306, # 数据库端口
'USER': 'wzy', # 数据库用户名
'PASSWORD': 'root1234', # 数据库密码
},
'my_sqlite3': {
'ENGINE': 'django.db.backends.sqlite3', # 链接数据库的类型
'NAME': os.path.join(BASE_DIR, 'sqlite3'), # 链接数据库的名字
}
}
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'Asia/Shanghai'
USE_I18N = True
USE_L10N = True
USE_TZ = True
AUTH_USER_MODEL = 'user.MyUser'
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]
if DEBUG:
RABBIT_HOST = '192.168.10.10'
QUEUE_TOPIC = 'logs'
RABBIT_USERNAME = 'wzy'
RABBIT_PASSWORD = 'root1234'
else:
RABBIT_HOST = '192.168.10.10'
QUEUE_TOPIC = 'logs'
RABBIT_USERNAME = 'wzy'
RABBIT_PASSWORD = 'root1234'
LOG_ROOT = os.path.join(BASE_DIR, 'logs') + os.sep
if DEBUG:
# 日志记录
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '%(asctime)s [%(name)s:%(lineno)d][%(module)s:%(funcName)s] [%(levelname)s]- %(message)s'},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
'file': {
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': LOG_ROOT + 'all.log',
'maxBytes': 1024*1024*5, # 文件大小
'backupCount': 10, # 备份份数
'formatter': 'standard',
},
'info': {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': LOG_ROOT + 'info.log',
'maxBytes': 1024*1024*5, # 文件大小
'backupCount': 10, # 备份份数
'formatter': 'standard',
},
'error': {
'level': 'WARNING',
'class': 'logging.handlers.RotatingFileHandler',
'filename': LOG_ROOT + 'error.log',
'maxBytes': 1024*1024*5, # 文件大小
'backupCount': 10, # 备份份数
'formatter': 'standard',
},
},
# 字别的模块中使用使用 import logging logger = logging.getLogger('django') getLogger 中的变量为 以下配置中内容
'loggers': {
'django': {
'handlers': ['file', 'console'],
'propagate': True,
},
'inf': {
'handlers': ['info', 'console'],
'level': 'INFO',
'propagate': True,
},
'err': {
'handlers': ['error', 'console'],
'level': 'WARNING',
'propagate': True,
},
# 查看数据库执行代码
'django.db.backends': {
'handlers': ['console', ],
'propagate': True,
'level': 'DEBUG',
},
},
}
else:
# 日志记录
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '%(asctime)s [%(name)s:%(lineno)d][%(module)s:%(funcName)s] [%(levelname)s]- %(message)s'},
},
'handlers': {
'console': {
'level': 'INFO', # DEBUG
'class': 'logging.StreamHandler',
},
'file': {
'level': 'INFO', # DEBUG
'class': 'logging.handlers.RotatingFileHandler',
'filename': LOG_ROOT + 'all.log',
'maxBytes': 1024 * 1024 * 5, # 文件大小
'backupCount': 10, # 备份份数
'formatter': 'standard',
},
'info': {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': LOG_ROOT + 'info.log',
'maxBytes': 1024 * 1024 * 5, # 文件大小
'backupCount': 10, # 备份份数
'formatter': 'standard',
},
'error': {
'level': 'WARNING',
'class': 'logging.handlers.RotatingFileHandler',
'filename': LOG_ROOT + 'error.log',
'maxBytes': 1024 * 1024 * 5, # 文件大小
'backupCount': 10, # 备份份数
'formatter': 'standard',
},
},
# 字别的模块中使用使用 import logging logger = logging.getLogger('django') getLogger 中的变量为 以下配置中内容
'loggers': {
'django': {
'handlers': ['file', 'console'],
'propagate': True,
},
'inf': {
'handlers': ['info', 'console'],
'level': 'INFO',
'propagate': True,
},
'err': {
'handlers': ['error', 'console'],
'level': 'WARNING',
'propagate': True,
},
# 查看数据库执行代码
'django.db.backends': {
'handlers': ['console', ],
'propagate': True,
'level': 'DEBUG',
},
},
}
pip install uwsgi
find / -name uwsgi
ln -r uwsgilujing /usr/bin/uwsgi
vi uwsgi.ini[uwsgi]
#使用nginx连接时使用,Django程序所在服务器地址
# socket=ip:80
#直接做web服务器使用,Django程序所在服务器地址
http=ip:80 注意:我用的腾讯云服务器,ip填写的是内网地址,不然报错bind(): Cannot assign requested address [core/socket.c line 769]
#项目目录
chdir=/root/program/WxFindInfo/mysite/
#项目中wsgi.py文件的目录,相对于项目目录
wsgi-file=mysite/wsgi.py
# 进程数
processes=4
# 线程数
threads=2
# uwsgi服务器的角色
master=True
# 存放进程编号的文件
pidfile=uwsgi.pid
# 日志文件,因为uwsgi可以脱离终端在后台运行,日志看不见。我们以前的runserver是依赖终端的
daemonize=uwsgi.log
uwsgi --ini uwsgi.ini
uwsgi --stop uwsgi.pid/kill -9 pid
uwsgi --reload uwsgi.pid
# mysite_uwsgi.ini file
[uwsgi]
chdir = /root/logsystem
#module = myshop.wsgi #testd����Ŀ���ƣ���testd.wsgi������ô�涨��д����û������ļ�
module= logsystem.wsgi:application
#static-map = /static=/root/logsystem/all_static_collect
buffer-size = 65536
master = true
processes = 2
socket = 127.0.0.1:8081
#http= 192.168.8.192:8081
#http-socket = 192.168.8.192:8081
#http://60.205.211.11 172.17.36.8
#http-socket = 172.17.36.8:8081
enable-threads = true
mule = common/dbutil.py
vacuum = true
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;
default_type application/octet-stream;
#log\_format main '$remote\_addr - $remote\_user \[$time\_local\] "$request" '
# '$status $body\_bytes\_sent "$http\_referer" '
# '"$http\_user\_agent" "$http\_x\_forwarded\_for"';
#access\_log logs/access.log main;
sendfile on;
#tcp\_nopush on;
#keepalive\_timeout 0;
keepalive\_timeout 65;
#gzip on;
upstream django {
#server unix:///path/to/your/mysite/mysite.sock; #
server 127.0.0.1:8080; # 8081
}
server {
listen 80;
server\_name localhost;
#charset koi8-r;
#access\_log logs/host.access.log main;
location / {
#root html;
#index index.html index.htm;
include /usr/local/nginx/conf/uwsgi\_params;
uwsgi\_pass django;
}
location /static/{
alias /root/logsystem/static\_collect/;
expires 30d;
autoindex on;
}
#error\_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error\_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \\.php$ {
# proxy\_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \\.php$ {
# root html;
# fastcgi\_pass 127.0.0.1:9000;
# fastcgi\_index index.php;
# fastcgi\_param SCRIPT\_FILENAME /scripts$fastcgi\_script\_name;
# include fastcgi\_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server\_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server\_name localhost;
# ssl\_certificate cert.pem;
# ssl\_certificate\_key cert.key;
# ssl\_session\_cache shared:SSL:1m;
# ssl\_session\_timeout 5m;
# ssl\_ciphers HIGH:!aNULL:!MD5;
# ssl\_prefer\_server\_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章