上一篇写了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

最新文章

  1. linux 命令行中常用光标移动快捷键
  2. 使用 RequireJS 优化 Web 应用前端
  3. 右键添加 CMD 命令提示符
  4. shell 判断文件是否存在
  5. struts2响应AJAX
  6. SQL Server 2008 无法保存表的更改
  7. java中的synchronized关键字
  8. linux下MySQL安装登录及操作
  9. java中说明书/开发文档如何编写?
  10. 笔记-AndroidStudio开发环境的搭建
  11. js 易错点
  12. [cocos2d-x] --- CCNode类详解
  13. RESTful摘要
  14. HQL中左连接,右连接、内连接
  15. 小程序之 tab切换(选项卡)
  16. OC 中property的使用
  17. 使用verdaccio 搭建npm私有仓库
  18. ES6模块化操作
  19. Http请求帮助类
  20. 【转】PHP之FastCGI与mod_php详解

热门文章

  1. [TS] Implement a singly linked list in TypeScript
  2. [Node] Stateful Session Management for login, logout and signup
  3. 对象的序列化与反序列化---IO学习笔记(四)
  4. 文字记录而已!!人民币直充/兑换PayPal美金
  5. caffe 在 windows 下的配置(scripts\build_win.cmd)
  6. cv2.putText 文字换行('\n')无法解析换行
  7. Android Studio将Eclipse的项目作为module的依赖库
  8. Intent传递对象的几种方式
  9. Android Material风格的应用(三)--DrawerLayout
  10. 从大整数乘法的实现到 Karatsuba 快速算法