上一篇写了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.com ServerName localhost
ServerAlias domain.com
ServerAdmin webmaster@localhost DocumentRoot /home/moma/Documents/domain_seo_tool Alias /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-packages WSGIProcessGroup 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:warn ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${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_application os.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

Django + Apache + wsgi配置和环境搭建(ubuntu)的更多相关文章

  1. windows下apache+wsgi+web.py环境搭建

    首先安装好wsgi模块并启用:1.下载地址:我本机是python2.7 http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi- ...

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

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

  3. Hadoop伪分布式环境搭建+Ubuntu:16.04+hadoop-2.6.0

    Hello,大家好 !下面就让我带大家一起来搭建hadoop伪分布式的环境吧!不足的地方请大家多交流.谢谢大家的支持 准备环境: 1, ubuntu系统,(我在16.04测试通过.其他版本请自行测试, ...

  4. Apache+PHP+MySQL+phpMyAdmin环境搭建

    最近在学习web服务端开发,一开始是使用wamp的,后来决定自己完整配置一下环境,并把整个过程记录下来.其中,Apache是服务器,php是用来编写服务端的语言,MySQL作为数据库,phpMyAdm ...

  5. django 1.11.16之环境搭建

    django版本:django1.11.16  windows环境 python 3.6.3    !!!可先安装虚拟环境在进行环境搭建  1.安装django:pip install django= ...

  6. 手把手教你 Apache DolphinScheduler 本地开发环境搭建 | 中英文视频教程

    点击上方 蓝字关注我们 最近,一些小伙伴反馈对小海豚的本地开发环境搭建过程不太了解,这不就有活跃的贡献者送来新鲜的视频教程!在此感谢@Tianqi-Dotes 的细致讲解 贡献者还贴心地录制了中英文两 ...

  7. Angularjs学习---angularjs环境搭建,ubuntu 12.04下安装nodejs、npm和karma

    1.下载angularjs 进入其官网下载:https://angularjs.org/‎,建议下载最新版的:https://ajax.googleapis.com/ajax/libs/angular ...

  8. tomcat配置及环境搭建

    步骤一 下载tomcat 下载tomcat并安装,登陆tomcat官网,http://tomcat.apache.org/,Windows系统建议选择Windows Service Installer ...

  9. apache+php+mysql开发环境搭建

    一.Apache       因为Apache官网只提供源代码,如果要使用必须得自己编译,这里我选择第三方安装包Apache Lounge. 进入Apachelounge官方下载地址:http://w ...

随机推荐

  1. AJAX - 封装的传参改为传入对象 XML JSON 数据格式

    Ajax封装函数,上次是直接传参,这次在原来的基础上改进,模仿jQuery 直接传入对象,把之前的参数都变为这个对象的属性. 这样可以随意调换传入数据的次序. 其他优点? 需要再复习一下. Ajax处 ...

  2. 推广一下新Blog www.hrwhisper.me

    新博客地址:www.hrwhisper.me 欢迎互访加友链~

  3. BZOJ2733: [HNOI2012]永无乡(线段树合并)

    Description 永无乡包含 n 座岛,编号从 1 到 n,每座岛都有自己的独一无二的重要度,按照重要度可 以将这 n 座岛排名,名次用 1 到 n 来表示.某些岛之间由巨大的桥连接,通过桥可以 ...

  4. BZOJ2002: [Hnoi2010]Bounce 弹飞绵羊(LCT)

    Description 某天,Lostmonkey发明了一种超级弹力装置,为了在 他的绵羊朋友面前显摆,他邀请小绵羊一起玩个游戏.游戏一开始,Lostmonkey在地上沿着一条直线摆上n个装置,每个装 ...

  5. CF1009F Dominant Indices(树上DSU/长链剖分)

    题目大意: 就是给你一棵以1为根的树,询问每一个节点的子树内节点数最多的深度(相对于这个子树根而言)若有多解,输出最小的. 解题思路: 这道题用树链剖分,两种思路: 1.树上DSU 首先想一下最暴力的 ...

  6. Android触摸事件(五)-CropBitmapActivity关于裁剪工具的使用

    文件夹 文件夹 概述 传递数据 裁剪流程 其他事项 使用方式 图片辅助功能 图片缩略图载入 图片旋转 源代码 GitHub地址 演示样例GIF 概述 这个Activity是为了裁剪图片的.使用时须要提 ...

  7. Flume Interceptors官网剖析(博主推荐)

    不多说,直接上干货! Flume Sources官网剖析(博主推荐) Flume Channels官网剖析(博主推荐) Flume Channel Selectors官网剖析(博主推荐) Flume ...

  8. 文件上传流式处理commons-fileupload

    1. 从请求中获取MultipartFile @RequestMapping(value="/upload", method=RequestMethod.POST) public ...

  9. jquery追加元素,移除DOM,jqueryDOM操作

    1.append() 方法在被选元素的结尾插入内容. 2.prepend() 方法在被选元素的开头插入内容. 3.after() 方法在被选元素之后插入内容. 4.before() 方法在被选元素之前 ...

  10. “焦点图/幻灯片”“Tab标签切换”“图片滚动”“无缝滚动”仅需一个SuperSlidev2.1

    官网:http://www.superslide2.com/index.html 1. 标签切换 / 书签切换 / 默认效果 2. 焦点图 / 幻灯片 3. 图片滚动-左 4. 图片滚动-上 5. 图 ...