Django生产环境的部署-Apache-mod_wsgi

httpd.conf配置

ServerSignature On
ServerTokens Full


Define APACHE24 Apache2.4
Define SERVER_BASE_DIR "D:/ProgramFiles/wamp" # 偷懒用了WAMP,这里就这么配置下
Define PYTHON_PATH "C:/Python27" # Python PATH
Define VIRTUALENV_HOME "D:/ProgramFiles/V" # 虚拟环境的PATH
Define PROJECT_BASE_DIR "E:/Users/zhangsan/Codes" # 项目代码PATH
Define DEMO_PORT 8080 # 分配给项目的监听的端口


ServerRoot "${SERVER_BASE_DIR}/bin/apache/apache2.4.9"
WSGIPythonHome "${PYTHON_PATH}"
WSGIPythonPath "${VIRTUALENV_HOME}/o/Lib/site-packages"


Listen 0.0.0.0:80
Listen [::0]:80
Listen ${DEMO_PORT}


# 下面的一些module属于WAMP默认开启的,一并放在下面
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule allowmethods_module modules/mod_allowmethods.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule cache_module modules/mod_cache.so
LoadModule cache_disk_module modules/mod_cache_disk.so
LoadModule cgi_module modules/mod_cgi.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
LoadModule file_cache_module modules/mod_file_cache.so
LoadModule include_module modules/mod_include.so
LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
LoadModule negotiation_module modules/mod_negotiation.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule vhost_alias_module modules/mod_vhost_alias.so


# LoadModule that project may needed
LoadModule filter_module modules/mod_filter.so
LoadModule headers_module modules/mod_headers.so
LoadModule mime_magic_module modules/mod_mime_magic.so

LoadModule proxy_module modules/mod_proxy.so # 需要反向代理的话,下面几个也是必要的
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
LoadModule wsgi_module modules/mod_wsgi.so # 这个是必要的.


<Files *.css>
    Header set Content-type "text/css"
</Files>
<Files *.js>
    Header set Content-type "application/javascript"
</Files>

LoadModule php5_module "D:/ProgramFiles/wamp/bin/php/php5.5.12/php5apache2_4.dll"

<IfModule unixd_module>
    User daemon
    Group daemon
</IfModule>

ServerAdmin admin@example.com

ServerName localhost:80

HostnameLookups Off

DocumentRoot "${SERVER_BASE_DIR}/www/"

<Directory />
    AllowOverride none
    ## Require all denied
    Require all granted
</Directory>


<Directory "${SERVER_BASE_DIR}/www/">
    Options Indexes FollowSymLinks
    AllowOverride all
    Require local
</Directory>



<IfModule dir_module>
    DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>

<Files ".ht*">
    Require all denied
</Files>

ErrorLog "${SERVER_BASE_DIR}/logs/apache_error.log"

LogLevel warn

<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common

    <IfModule logio_module>
      LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>

    CustomLog "${SERVER_BASE_DIR}/logs/access.log" common

</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "${SERVER_BASE_DIR}/bin/apache/apache2.4.9/cgi-bin/"

</IfModule>

<IfModule cgid_module>
</IfModule>

<Directory "${SERVER_BASE_DIR}/bin/apache/apache2.4.9/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule mime_module>
    TypesConfig conf/mime.types
    AddEncoding x-compress .Z
    AddEncoding x-gzip .gz .tgz
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .php3
</IfModule>

EnableSendfile off

AcceptFilter http none
AcceptFilter https none

Include conf/extra/httpd-autoindex.conf

<IfModule proxy_html_module>
    Include conf/extra/proxy-html.conf
</IfModule>

<IfModule ssl_module>
    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin
</IfModule>

Include "${SERVER_BASE_DIR}/alias/*"  # 项目的实际的配置项由外部引入,保留httpd.conf的完整性,这是有好处的

Define APP_BASE_DIR_BASE_DIR "${PROJECT_BASE_DIR}/appname" # 定义 Application

<VirtualHost *:${DEMO_PORT}>
    DocumentAPP_BASE_DIR "${APP_BASE_DIR}"
    # ServerName my-demo.com
    WSGIScriptAlias / "${APP_BASE_DIR}/core/wsgi.py"

    <Directory "${APP_BASE_DIR}/core">
       <Files wsgi.py>
           Require all granted
       </Files>
    </Directory>

    Alias /static "${APP_BASE_DIR}/static"
    <Directory "${APP_BASE_DIR}/files/static">
        Require all granted
    </Directory>

    # <Location /ws>
    #     ProxyPass ws://127.0.0.1:8001/ws
    #     ProxyPassReverse ws://127.0.0.1:8001/ws
    # </Location>

    # <Location /ipython>
    #     ProxyPreserveHost On
    #     ProxyPass http://127.0.0.1:8002/ipython
    #     ProxyPassReverse http://127.0.0.1:8002/ipython
    #     ProxyPass ws://127.0.0.1:8002/ipython
    #     ProxyPassReverse ws://127.0.0.1:8002/ipython
    #     Header set Origin "http://127.0.0.1:8002/"
    #     RequestHeader set Origin "http://127.0.0.1:8002/"
    # </Location>
</VirtualHost>

demo明天附上

posted @ 2015-02-06 18:28  Mx.Hu  阅读(433)  评论(0编辑  收藏  举报