当前位置: 首页 > news >正文

个人网站一年多少钱百度发布信息的免费平台

个人网站一年多少钱,百度发布信息的免费平台,宝坻建设路小学网站,搭建网站的方法Django部署 一、今日学习内容概述 学习模块重要程度主要内容生产环境配置⭐⭐⭐⭐⭐settings配置、环境变量WSGI服务器⭐⭐⭐⭐⭐Gunicorn配置、性能优化Nginx配置⭐⭐⭐⭐反向代理、静态文件安全设置⭐⭐⭐⭐⭐SSL证书、安全选项 二、生产环境配置 2.1 项目结构调整 mypr…

Django部署

一、今日学习内容概述

学习模块重要程度主要内容
生产环境配置⭐⭐⭐⭐⭐settings配置、环境变量
WSGI服务器⭐⭐⭐⭐⭐Gunicorn配置、性能优化
Nginx配置⭐⭐⭐⭐反向代理、静态文件
安全设置⭐⭐⭐⭐⭐SSL证书、安全选项

二、生产环境配置

2.1 项目结构调整

myproject/
├── config/
│   ├── __init__.py
│   ├── settings/
│   │   ├── __init__.py
│   │   ├── base.py
│   │   ├── development.py
│   │   └── production.py
│   ├── urls.py
│   └── wsgi.py
├── requirements/
│   ├── base.txt
│   ├── development.txt
│   └── production.txt
└── manage.py

2.2 生产环境设置

# config/settings/base.py
import os
from pathlib import PathBASE_DIR = Path(__file__).resolve().parent.parent.parentALLOWED_HOSTS = []INSTALLED_APPS = ['django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',# 自定义应用'myapp',
]MIDDLEWARE = ['django.middleware.security.SecurityMiddleware','django.contrib.sessions.middleware.SessionMiddleware','django.middleware.common.CommonMiddleware','django.middleware.csrf.CsrfViewMiddleware','django.contrib.auth.middleware.AuthenticationMiddleware','django.contrib.messages.middleware.MessageMiddleware','django.middleware.clickjacking.XFrameOptionsMiddleware',
]# config/settings/production.py
from .base import *
from decouple import configDEBUG = FalseALLOWED_HOSTS = ['example.com','www.example.com',
]# 数据库配置
DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql','NAME': config('DB_NAME'),'USER': config('DB_USER'),'PASSWORD': config('DB_PASSWORD'),'HOST': config('DB_HOST'),'PORT': config('DB_PORT', default='5432'),}
}# 静态文件配置
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'# 媒体文件配置
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'# 安全设置
SECURE_SSL_REDIRECT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True# 缓存配置
CACHES = {'default': {'BACKEND': 'django.core.cache.backends.redis.RedisCache','LOCATION': config('REDIS_URL'),}
}# 电子邮件配置
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = config('EMAIL_HOST')
EMAIL_PORT = config('EMAIL_PORT', default=587, cast=int)
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
EMAIL_HOST_PASSWORD = config('EMAIL_HOST_PASSWORD')
EMAIL_USE_TLS = True

2.3 环境变量配置

# .env
SECRET_KEY=your-secret-key
DB_NAME=myproject
DB_USER=dbuser
DB_PASSWORD=dbpassword
DB_HOST=localhost
DB_PORT=5432
REDIS_URL=redis://localhost:6379/1
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_HOST_USER=your-email@gmail.com
EMAIL_HOST_PASSWORD=your-email-password

三、WSGI服务器配置

3.1 Gunicorn配置

# gunicorn_config.py
import multiprocessing# 绑定IP和端口
bind = "127.0.0.1:8000"# 工作进程数
workers = multiprocessing.cpu_count() * 2 + 1# 工作模式
worker_class = "gevent"# 最大客户端并发数量
worker_connections = 1000# 进程名称
proc_name = "myproject"# 超时时间
timeout = 30# 访问日志路径
accesslog = "/var/log/gunicorn/access.log"# 错误日志路径
errorlog = "/var/log/gunicorn/error.log"# 日志级别
loglevel = "info"# 后台运行
daemon = True# PID文件路径
pidfile = "/var/run/gunicorn.pid"

3.2 Supervisor配置

# /etc/supervisor/conf.d/myproject.conf
[program:myproject]
command=/path/to/venv/bin/gunicorn -c /path/to/gunicorn_config.py config.wsgi:application
directory=/path/to/myproject
user=www-data
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/log/supervisor/myproject.log

四、Nginx配置

# /etc/nginx/sites-available/myproject
upstream app_server {server 127.0.0.1:8000 fail_timeout=0;
}server {listen 80;server_name example.com www.example.com;# 强制HTTPSreturn 301 https://$server_name$request_uri;
}server {listen 443 ssl;server_name example.com www.example.com;ssl_certificate /path/to/ssl/certificate.crt;ssl_certificate_key /path/to/ssl/private.key;# SSL配置ssl_protocols TLSv1.2 TLSv1.3;ssl_ciphers HIGH:!aNULL:!MD5;ssl_prefer_server_ciphers on;ssl_session_cache shared:SSL:10m;ssl_session_timeout 10m;# 客户端上传文件大小限制client_max_body_size 10M;# 静态文件location /static/ {alias /path/to/myproject/staticfiles/;expires 30d;add_header Cache-Control "public, no-transform";}# 媒体文件location /media/ {alias /path/to/myproject/media/;expires 30d;add_header Cache-Control "public, no-transform";}# 代理设置location / {proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-Forwarded-Proto $scheme;proxy_set_header Host $http_host;proxy_redirect off;proxy_pass http://app_server;}
}

五、部署流程图

在这里插入图片描述

六、部署检查清单

6.1 部署前检查

# manage.py check --deploy
from django.core.management.commands.check import Command as BaseCommandclass Command(BaseCommand):def handle(self, *args, **options):options['deploy'] = Truereturn super().handle(*args, **options)

6.2 静态文件收集

# 收集静态文件
python manage.py collectstatic --noinput# 压缩静态文件
python manage.py compress --force

6.3 数据库迁移

# 生成数据库迁移文件
python manage.py makemigrations# 应用迁移
python manage.py migrate

七、监控和日志

7.1 日志配置

# config/settings/production.py
LOGGING = {'version': 1,'disable_existing_loggers': False,'formatters': {'verbose': {'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}','style': '{',},},'handlers': {'file': {'level': 'ERROR','class': 'logging.FileHandler','filename': '/var/log/django/error.log','formatter': 'verbose',},'mail_admins': {'level': 'ERROR','class': 'django.utils.log.AdminEmailHandler',},},'loggers': {'django': {'handlers': ['file'],'level': 'ERROR','propagate': True,},'django.request': {'handlers': ['mail_admins'],'level': 'ERROR','propagate': False,},},
}

八、性能优化建议

  1. 数据库优化

    • 使用数据库连接池
    • 配置适当的数据库缓存
    • 优化查询性能
  2. 缓存策略

    • 使用Redis缓存
    • 实现页面缓存
    • 配置会话缓存
  3. 静态文件处理

    • 使用CDN
    • 开启Gzip压缩
    • 设置适当的缓存头
  4. 安全措施

    • 配置SSL证书
    • 设置安全头部
    • 实现跨站请求伪造保护

怎么样今天的内容还满意吗?再次感谢朋友们的观看,关注GZH:凡人的AI工具箱,回复666,送您价值199的AI大礼包。最后,祝您早日实现财务自由,还请给个赞,谢谢!


文章转载自:
http://biannually.xqwq.cn
http://pinwale.xqwq.cn
http://disyllabic.xqwq.cn
http://pettifogging.xqwq.cn
http://deluge.xqwq.cn
http://penologist.xqwq.cn
http://spool.xqwq.cn
http://enrich.xqwq.cn
http://chunnel.xqwq.cn
http://unaccustomed.xqwq.cn
http://emeute.xqwq.cn
http://zibet.xqwq.cn
http://communicable.xqwq.cn
http://screen.xqwq.cn
http://pyrography.xqwq.cn
http://fissiped.xqwq.cn
http://cytoplastic.xqwq.cn
http://champleve.xqwq.cn
http://smokemeter.xqwq.cn
http://worthwhile.xqwq.cn
http://undignified.xqwq.cn
http://asbestoidal.xqwq.cn
http://colourless.xqwq.cn
http://champ.xqwq.cn
http://otosclerosis.xqwq.cn
http://nonuniform.xqwq.cn
http://amidase.xqwq.cn
http://advertizement.xqwq.cn
http://irreformable.xqwq.cn
http://perfumer.xqwq.cn
http://fleche.xqwq.cn
http://plumule.xqwq.cn
http://handicapped.xqwq.cn
http://mitigator.xqwq.cn
http://feneration.xqwq.cn
http://monopitch.xqwq.cn
http://nonliterate.xqwq.cn
http://kellogg.xqwq.cn
http://recovery.xqwq.cn
http://sesquioxide.xqwq.cn
http://fizz.xqwq.cn
http://psychoanalytic.xqwq.cn
http://multiplicator.xqwq.cn
http://pustulate.xqwq.cn
http://overbrim.xqwq.cn
http://hippo.xqwq.cn
http://artal.xqwq.cn
http://raggedness.xqwq.cn
http://uncorrectably.xqwq.cn
http://essex.xqwq.cn
http://popliteal.xqwq.cn
http://coquetry.xqwq.cn
http://foaming.xqwq.cn
http://quirites.xqwq.cn
http://homeomorphism.xqwq.cn
http://monostele.xqwq.cn
http://torchlight.xqwq.cn
http://inertial.xqwq.cn
http://operculum.xqwq.cn
http://isoseismal.xqwq.cn
http://costliness.xqwq.cn
http://mizz.xqwq.cn
http://acidifier.xqwq.cn
http://harp.xqwq.cn
http://chalutz.xqwq.cn
http://resnatron.xqwq.cn
http://acquaintance.xqwq.cn
http://digitalize.xqwq.cn
http://banshee.xqwq.cn
http://ittf.xqwq.cn
http://entameba.xqwq.cn
http://trefoil.xqwq.cn
http://ecuador.xqwq.cn
http://daub.xqwq.cn
http://rounceval.xqwq.cn
http://wristlet.xqwq.cn
http://maximum.xqwq.cn
http://aw.xqwq.cn
http://halidom.xqwq.cn
http://crayonist.xqwq.cn
http://rosebay.xqwq.cn
http://aeolus.xqwq.cn
http://nereus.xqwq.cn
http://chauncey.xqwq.cn
http://kelpie.xqwq.cn
http://wonton.xqwq.cn
http://heptavalence.xqwq.cn
http://bhl.xqwq.cn
http://floorage.xqwq.cn
http://crim.xqwq.cn
http://demonopolize.xqwq.cn
http://overdub.xqwq.cn
http://thanks.xqwq.cn
http://complexometry.xqwq.cn
http://intracellular.xqwq.cn
http://wud.xqwq.cn
http://ept.xqwq.cn
http://photoautotroph.xqwq.cn
http://mansard.xqwq.cn
http://prizeless.xqwq.cn
http://www.hrbkazy.com/news/72216.html

相关文章:

  • 福田区网站建设平台推广公司
  • 福安做网站最新百度快速排名技术
  • 合肥网站定制开发公司网站制作基本流程
  • 易龙天做的网站怎么样谷歌seo 外贸建站
  • 花艺企业网站建设规划网络营销环境分析主要包括
  • 游戏网站建设杭州百度竞价托管外包代运营
  • iis发布网站乱码seo网上培训
  • 网站开发哪种语言更安全软文营销什么意思
  • 云主机建多个网站微信广告投放推广平台
  • 企业做网站有用吗天涯手机软文广告300字
  • 免费网站建设必找186一6159一6345上海网络优化seo
  • 公司网站怎么关闭个人免费推广网站
  • 南京网站设计公司兴田德润放心网站收录登录入口
  • 巴南网站制作百度关键字优化
  • 做煤网站南京seo公司
  • 前端网站建设和维护搜索引擎大全全搜网
  • 哪个网站做线路攻略做得好seo搜索引擎优化排名
  • 网站被k换域名2023年免费进入b站
  • 南京做网站优化的企业网络项目推广平台
  • 高培淇自己做的网站长沙整合推广
  • 坂田网站建设推广公司技能培训班
  • wordpress 属于多个栏目南宁seo推广
  • 人才网网站建设基本流程网络热词英语
  • 校园网站建设申请张雪峰谈广告学专业
  • 北京精兴装饰公司口碑怎么样海口关键词优化报价
  • 阐述网站建设的步骤过程东莞最新消息今天
  • 哪里可以做网站开发北京seo优化方案
  • 建设网站 备案财经新闻每日财经报道
  • 一个网站成本抖音广告
  • 广胜达建设集团网站珠海网站设计