上一篇写了Django + nginx + uwsgi配置和环境搭建(ubuntu)
由于公司服务器环境问题,又配置了apache的环境。记录例如以下:

一. 安装环境:

#apache
sudo apt-get install apache2# Python 2
sudo apt-get install libapache2-mod-wsgi

二. django:
2.1 保证站点能执行:
根文件夹执行:python manage.py runserver 0.0.0.0:1111
能在0.0.0.0:1111訪问到,说明正常

2.2 static和media文件
setting.py中添加:STATIC_ROOT = os.path.join(BASE_DIR, "static/")
执行python manage.py collectstatic

三. apache:
/etc/apache2/sites-available/aaaa.conf中配置

<VirtualHost *:2222># The ServerName directive sets the request scheme, hostname and port that# the server uses to identify itself. This is used when creating# redirection URLs. In the context of virtual hosts, the ServerName# specifies what hostname must appear in the request's Host: header to# match this virtual host. For the default virtual host (this file) this# value is not decisive as it is used as a last resort host regardless.# However, you must set it for any further virtual host explicitly.#ServerName www.example.comServerName localhostServerAlias domain.comServerAdmin webmaster@localhostDocumentRoot /home/moma/Documents/domain_seo_toolAlias /media/ /home/moma/Documents/domain_seo_tool/media/Alias /static/ /home/moma/Documents/domain_seo_tool/static/WSGIScriptAlias / /home/moma/Documents/domain_seo_tool/domain_seo_tool/wsgi.py<Directory /home/moma/Documents/domain_seo_tool/media/>Require all granted</Directory><Directory /home/moma/Documents/domain_seo_tool/static/>Require all granted</Directory>WSGIDaemonProcess domain_seo_tool user=moma group=moma processes=2 threads=25 python-path=/usr/local/lib/python2.7/site-packagesWSGIProcessGroup domain_seo_tool#某些版本号下不须要一下5条。但某些会apache出现forbidden现象,加上保证执行,apache error log中出现client denied by server configuration<Directory /home/moma/Documents/domain_seo_tool/domain_seo_tool><Files wsgi.py>Require all granted</Files></Directory># Available loglevels: trace8, ..., trace1, debug, info, notice, warn,# error, crit, alert, emerg.# It is also possible to configure the loglevel for particular# modules, e.g.#LogLevel info ssl:warnErrorLog ${APACHE_LOG_DIR}/error.logCustomLog ${APACHE_LOG_DIR}/access.log combined# For most configuration files from conf-available/, which are# enabled or disabled at a global level, it is possible to# include a line for only one particular virtual host. For example the# following line enables the CGI configuration for this host only# after it has been globally disabled with "a2disconf".#Include conf-available/serve-cgi-bin.conf
</VirtualHost>

注意:

上述配置中标记的地方,但某些会apache出现forbidden现象,加上保证执行,apache error log中出现client denied by server configuration,百度上的一些答案都不靠谱,解决这个问题还是得靠stackover flow

django:
wsgi.py 文件
改动成:

"""
WSGI config for domain_seo_tool project.It exposes the WSGI callable as a module-level variable named ``application``.For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
"""import os, sys
sys.path.append('/var/www/domain_seo_tool_apache/domain_seo_tool')#添加的
sys.path.append('/var/www/domain_seo_tool_apache/domain_seo_tool /domain_seo_tool')#添加的from django.core.wsgi import get_wsgi_applicationos.environ.setdefault("DJANGO_SETTINGS_MODULE", "domain_seo_tool.settings")application = get_wsgi_application()

须要添加系统路径。否则报错:

Target WSGI script
‘/var/www/domain_seo_tool_apache/domain_seo_tool/wsgi.py’ cannot be
loaded as Python module
以及
ImportError: Could not import settings ‘domain_seo_tool.settings’ (Is it on sys.path? Is there an import error in the settings file?): No module named domain_seo_tool.settings

转载于:https://www.cnblogs.com/llguanli/p/7249888.html

Django + Apache + wsgi配置和环境搭建(ubuntu)相关推荐

  1. Django Python MySQL Linux 开发环境搭建

    Django Python MySQL Linux 开发环境搭建 1.安装Python 进行Python开发,首先必须安装python,对于linux 或者Mac 用户,python已经预装. 在命令 ...

  2. apache+tomcat集群环境搭建

    apache+tomcat集群环境搭建 1. 什么是集群         简单理解就是:将项目同时部署在多台服务器上(tomcat)运行,通过一个web服务器(Apache/nginx)进行请求分发和 ...

  3. 陈力:传智播客古代 珍宝币 泡泡龙游戏开发第十九讲:apache+php+mysql开发环境搭建(wamp)

    陈力:传智播客古代 珍宝币 泡泡龙游戏开发第十九讲:apache+php+mysql开发环境搭建(wamp) window环境下进行网站建设时,必须要进行wamp环境的搭建.本文介绍了如果配置apac ...

  4. 【Django基础01】_环境搭建和后台管理

    一.一般公司结构简介 在接触python框架学习之前,首先要清楚我们做项目的基本架构,项目组以及公司的基本分类.下面我简单做一下梳理,仅供参考. 1.项目组 (1)产品---2个人,提需求(女生为主) ...

  5. yii2环境搭建(ubuntu下nginx+php+mysql+yii2)

    2019独角兽企业重金招聘Python工程师标准>>> 系统版本:ubuntu版本14.04 x86_64 nginx版本:1.4.6 (默认命令安装版本) PHP版本:php-5. ...

  6. 嵌入式开发基本环境搭建---ubuntu

    嵌入式基本环境搭建 嵌入式Linux环境 win10 + WSL git环境安装 将远程仓库关联本地 samba服务器搭建 samba环境搭建 samba配置相关 问题解决措施 gcc编译器安装 几种 ...

  7. 《嵌入式系统 - RT-Thread开发笔记》 第三部分 RT-Thread 移植与设备驱动开发 - 第1章 RT-Thread 开发环境搭建 (Ubuntu)

    开发环境: Ubuntu:16.04 LTS 开发板:stm32f746-st-nucleo 开发板MCU:STM32F746ZG 1.1准备工作 1.1.1下载源码与安装环境 更新软件源: $ su ...

  8. [xbttracker] linux 下 xbt tracker环境搭建(ubuntu)

    系统环境:Ubuntu x64 20.04 操作系统:win10 xbt源码:  https://github.com/dangwei-90/xbt 参考文档:http://xbtt.sourcefo ...

  9. 【django接口自动化1】环境搭建

    目录 一.下载python 二.下载pycharm 三.sudo pip install django 四.django-project目录详解 五.创建sign app 六.查看sign app的目 ...

最新文章

  1. ecplise 设置代码自动提示功能的设置
  2. 使用NLTK进行英文分词
  3. python基础教程第三版怎么样-Python基础教程(第三版)(七)再谈抽象
  4. 【机器学习——决策树】——两种方法实现,含模型的保存和调用
  5. 阻止a链接跳转方法总结
  6. oracle当查询没有输出返回0,ORACLE技术问题专家问答五则
  7. P1533 可怜的狗狗
  8. 《编程之美》第2刷勘误
  9. python︱imagehash中的四种图像哈希方式(phash/ahash/dhash/小波hash)
  10. Excel基础(13)日期函数
  11. P4234 最小差值生成树
  12. 机器学习笔记 - 优化简介
  13. html 手机录视频,手机怎么录制视频 怎么用手机录视频?
  14. 如何修改apk文件,反编译(转)
  15. 如何轻松愉快的搞定产品经理面试
  16. 总结2019,憧憬2020
  17. mooc程序设计与算法(三)C++面向对象程序设计 类和对象提高 编程作业 5:魔兽世界之一:备战
  18. The JAVA_HOME environment variable is not defined correctly This environment variable is needed to r
  19. 使用canvas制作绘图板
  20. Linux 下进程相关的常用命令汇总

热门文章

  1. 换手率与股价成交量 关系
  2. 漫步数理统计十一——连续随机变量(下)
  3. 吴恩达深度学习 —— 3.2 神经网络表示
  4. Spring集成单元测试
  5. golang map合并_Golang之流式编程
  6. apereo cas开发_Apereo CAS Server服务端搭建教程
  7. java复制文件夹_java实现拷贝一个文件夹,里面存在目录和文件,使用文件创建和文件流...
  8. mysql limit 表的长度_mysql中的limit用法有哪些(推荐)
  9. 测试鬼的软件是假的吗,中国被禁止的6种测鬼方法 证实鬼魂真实存在(谣言)
  10. 电脑上win是哪个键_电脑按哪个键是切换拼音输入法