在apache服务器上部署两个django项目总结

    xiaoxiao2021-04-11  36

    环境说明:

    Windows server2003(64) + Apache2.2 + python2.7.11 + django1.11

     

    项目路径说明:

    两个django项目分别为aaabbb,与apache在同一个目录Apache Software Foundation,即在Apache Software Foundation文件夹下有Apache2.2  aaa  bbb 三个文件夹,

     

    单个django项目在apache的部署参考这篇博客:http://www.cnblogs.com/fnng/p/4119712.html

     

    端口监听在http.conf文件中设置为:

    Listen 80

     

    http.conf中设置Servername127.0.0.1

    正文:

     

    1.首先,下载pythonweb服务器网关接口wsgi,将其命名为mod_wsgi.so,并添加到Apache2.2modules目录下

     

    2.Apache2.2conf目录下的httpd.conf文件中加入以下代码以让apache加载wsgi模块:

    LoadModule wsgi_module modules/mod_wsgi.so

     

    3. httpd.conf 文件中加入以下代码说明python 环境路径:

    WSGIPythonPath "C:/Python27/Lib;C:/Python27/Lib/site-packages;C:/Python27/DLLs"

    WSGIPythonHome "C:/Python27"

     

    4.apache在启动时能加载虚拟主机模块。打开httpd.conf 文件,找到一下两行代码,将前面的#删掉:

    #LoadModule vhost_alias_module modules/mod_vhost_alias.so

    #Include conf/extra/httpd-vhosts.conf  

     

    5. httpd.conf 中添加我们django项目的目录,到aaa 和bbb所在层级就行了:

     

    <Directory "D:/Program Files (x86)/Apache Software Foundation">

        #

        # Possible values for the Options directive are "None", "All",

     # or any combination of:

        #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews

        #

        # Note that "MultiViews" must be named *explicitly* --- "Options All"

        # doesn't give it to you.

        #

        # The Options directive is both complicated and important.  Please see

        # http://httpd.apache.org/docs/2.2/mod/core.html#options

        # for more information.

        #

        Options Indexes FollowSymLinks

     

        #

        # AllowOverride controls what directives may be placed in .htaccess files.

        # It can be "All", "None", or any combination of the keywords:

        #   Options FileInfo AuthConfig Limit

        #

        AllowOverride None

     

        #

        # Controls who can get stuff from this server.

        #

        Order allow,deny

        Allow from all

     

    </Directory>

     

    6.<IfModule alias_module>标签内添加 :

    ScriptAlias /cgi-bin/D:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin

     

    7.修改cgi-bin目录为:

    <Directory "D:/Program Files (x86)/Apache Software Foundation/Apache2.2/cgi-bin">

        AllowOverride None

        Options None

        Order allow,deny

        Allow from all

    </Directory>

     

     

    8.接下来,保存并关闭以上我们修改的httpd.conf文件,打开 conf文件夹下的extra文件,找到

    httpd-vhosts.conf 文件并打开做修改:

     

    <VirtualHost *:80>  

      ServerName xxx.com

    ServerAlias www.xxx.com

      WSGIScriptAlias / "D:/Program Files (x86)/Apache Software Foundation/aaa/aaa/wsgi.py"

     

      Alias /static "D:/Program Files (x86)/Apache Software Foundation/aaa/mysite1/static"  

      <Directory "D:/Program Files (x86)/Apache Software Foundation/aaa/mysite1/static">     

        Allow from all   

      </Directory>     

      

      DocumentRoot "D:/Program Files (x86)/Apache Software Foundation/aaa"  

      <Directory "D:/Program Files (x86)/Apache Software Foundation/aaa">  

            Options Indexes FollowSymLinks  

            AllowOverride None  

      </Directory>  

    </virtualHost>  

      

     

    <VirtualHost *:80>  

      ServerName yyy.com

      

      ServerAlias www.yyy.com

      WSGIScriptAlias / "D:/Program Files (x86)/Apache Software Foundation/bbb/bbb/wsgi.py"

        

      Alias /static "D:/Program Files (x86)/Apache Software Foundation/bbb/mysite2/static"  

      <Directory "D:/Program Files (x86)/Apache Software Foundation/bbb/mysite2/static">     

        Allow from all

      </Directory>     

      

      DocumentRoot "D:/Program Files (x86)/Apache Software Foundation/bbb"  

      <Directory "D:/Program Files (x86)/Apache Software Foundation/bbb">  

            Options Indexes FollowSymLinks  

            AllowOverride None  

      </Directory>  

    </virtualHost>  

     

    9.最后,打开两个项目的wsgi.py文件,把我们的项目加进去即可;

      import sys    

      sys.path.append('D:/Program Files (x86)/Apache Software Foundation/aaa) 

     

    10.重启apache即可 

    转载请注明原文地址: https://ju.6miu.com/read-667035.html

    最新回复(0)