简体   繁体   English

在Windows上为Wamp Server配置mod_wsgi

[英]Configuring mod_wsgi for wamp server on windows

I am new in Django development. 我是Django开发的新手。 I have created an Django application and tested in development server ie 127.0.0.1:8080/mysite. 我创建了一个Django应用程序,并在开发服务器即127.0.0.1:8080/mysite中进行了测试。 Then I decided to run this app on Apache server 2.4.9. 然后,我决定在Apache服务器2.4.9上运行此应用程序。 As all we know the best option is configuring mod_wsgi. 众所周知,最好的选择是配置mod_wsgi。 My problem is Apache server never runs after configuring as bellow: 我的问题是配置为以下情况后,Apache服务器永远无法运行:

  1. Keep mod_wsgi.so downloaded on 'C:\\wamp\\bin\\apache\\apache2.4.9\\modules\\'. 保持将mod_wsgi.so 下载到“ C:\\ wamp \\ bin \\ apache \\ apache2.4.9 \\ modules \\”上。
  2. Insert "LoadModule wsgi_module modules/mod_wsgi.so" to httpd.conf 将“ LoadModule wsgi_module modules / mod_wsgi.so”插入httpd.conf
  3. Restart wamp server 重启wamp服务器

I am using 32 bit of Python,Apache and mod_wsgi. 我正在使用32位的Python,Apache和mod_wsgi。 Python is installed for all user. 为所有用户安装了Python。 Please help me - 请帮我 -

First of all copy mod_wgi in modules folder, then add following to httpd.conf modules list: 首先在模块文件夹中复制mod_wgi,然后将以下内容添加到httpd.conf模块列表:

LoadModule wsgi_module modules/mod_wsgi.so

attention that naming is important (should suffix with _module) 注意命名很重要(应在_module后缀)

Add the following to your httpd.conf 将以下内容添加到您的httpd.conf中

Include path_to_your_proj/django_wsgi.conf

django_wsgi.conf file: django_wsgi.conf文件:

 WSGIScriptAlias path_to/django.wsgi

<Directory project_path>
   Allow from all
   Order allow,deny
</Directory>

Alias /static path_to_static_files

django.wsgi file: django.wsgi文件:

import os
import sys

#Calculate the path based on the location of the WSGI script.
CURRENT_DIR = os.path.dirname(__file__).replace('\\','/')
PROJECT_ROOT = os.path.abspath(os.path.join(CURRENT_DIR, os.pardir))
SETTINGS_DIR = os.path.join(PROJECT_ROOT,'proj_dir_name')

if PROJECT_ROOT not in sys.path:
    sys.path.append(PROJECT_ROOT)
if SETTINGS_DIR not in sys.path:
    sys.path.append(SETTINGS_DIR)

os.chdir(SETTINGS_DIR)
os.environ['DJANGO_SETTINGS_MODULE'] = 'proj_name.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

If you're using a virtualenv (that I suggest) do as follows: 如果您使用的是virtualenv(我建议),请执行以下操作:

httpd.conf file: httpd.conf文件:

# virtual env02
<VirtualHost ip-adddress_or_dns:port_if_other_than_80>
    ServerName just_a_name     # like : app01
    ServerAlias just_an_alias #  like : app01.mydomain.com
    ErrorLog "logs/env02.error.log"
    CustomLog "logs/env02.access.log" combined
    WSGIScriptAlias /  direct_path_to_you_wsgi_with_forward_slashes # like:  C:/virtual/venv01/proj_name/wsgi.py
    <Directory proj_dir_with_forward_slashed>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    Alias /static path_to_static_folder_with_forward_slashes
    <Directory path_to_static_folder_with_forward_slashes>
        Require all granted
    </Directory>  
</VirtualHost>
# end virtual env02

wsgi.py file: wsgi.py文件:

activate_this = 'c:/virtual/env02/scripts/activate_this.py'
# execfile(activate_this, dict(__file__=activate_this))
exec(open(activate_this).read(),dict(__file__=activate_this))

import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('c:/Organizer/virtual/env02/Lib/site-packages')

# Add the app's directory to the PYTHONPATH
sys.path.append('c:/virtual/proj_name')
sys.path.append('c:/virtual/proj_name/default_app_name')

os.environ['DJANGO_SETTINGS_MODULE'] = 'default_app_name.settings'

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "default_app_name.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM