Apache 部署 django

一、安装 Apache  

1、下载Apache    http://httpd.apache.org/

2、解压到目录 E:\Apache24

3、修改 httpd.conf

     Define SRVROOT "E:\Apache24"

     ServerRoot "${SRVROOT}"

  Listen 8089   //更改端口

4、运行服务 httpd.exe 

5、浏览器打开 http://127.0.0.1:8089 则成功,或8089端口被占用

二、安装 mod_wsgi

1、下载mod_wsgi   http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi

2、安装 mod_wsgi   pip install mod_wsgi-4.5.17+ap24vc10-cp34-cp34m-win_amd64.whl

3、运行mod_wsgi-express module-config 
#输出 后面部署Django+Apache需要以下的输出内容

LoadFile "c:/users/administrator/appdata/local/programs/python/python36-32/python36.dll"

LoadModule wsgi_module "c:/users/administrator/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"

WSGIPythonHome "c:/users/administrator/appdata/local/programs/python/python36-32"

三、修改httpd.conf 配置环境

#安装wsgi模块后,出来的三行字符,直接复制过来
LoadFile "c:/users/administrator/appdata/local/programs/python/python36-32/python36.dll"
LoadModule wsgi_module "c:/users/administrator/appdata/local/programs/python/python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"
WSGIPythonHome "c:/users/administrator/appdata/local/programs/python/python36-32"

#设置工程中的wsgi路径
WSGIScriptAlias / E:\em_pj\em_pj\wsgi.py
#设置工程路径
WSGIPythonPath E:\em_pj
#设置wsgi路径

    
        Require all granted
    

#设置静态文件路径
Alias /static E:\em_pj\static_temp
  #static_temp 为  static_root 所指示的静态文件收集文件夹 
    AllowOverride None
    Options None
    Require all granted

四、修改django  setting 文件

1、DEBUG = False

2、

STATIC_ROOT = os.path.join(BASE_DIR,'static_temp')
STATICFILES_DIRS = (os.path.join(BASE_DIR,'static'),        
                    os.path.join(BASE_DIR,  "static"), )   # 静态文件目录

3、cmd  收集静态文件  python manage.py collectstatic

4、重新启动apache  管理服务

你可能感兴趣的:(python,Django,服务器,django)