在Windows上为Wamp Server配置mod_wsgi [英] Configuring mod_wsgi for wamp server on windows
问题描述
我是Django开发的新手.我创建了一个Django应用程序并在开发服务器中进行了测试,即127.0.0.1:8080/mysite.然后,我决定在Apache服务器2.4.9上运行此应用程序.众所周知,最好的选择是配置mod_wsgi.我的问题是配置为波纹管后,Apache服务器永远无法运行:
I am new in Django development. I have created an Django application and tested in development server i.e. 127.0.0.1:8080/mysite. Then I decided to run this app on Apache server 2.4.9. As all we know the best option is configuring mod_wsgi. My problem is Apache server never runs after configuring as bellow:
- 保留mod_wsgi.so
下载到了"C:\ wamp \ bin \ apache \ apache2.4.9 \ modules \"上. - 将"LoadModule wsgi_module modules/mod_wsgi.so"插入httpd.conf
- 重新启动wamp服务器
- Keep mod_wsgi.so downloaded on 'C:\wamp\bin\apache\apache2.4.9\modules\'.
- Insert "LoadModule wsgi_module modules/mod_wsgi.so" to httpd.conf
- Restart wamp server
我正在使用32位的Python,Apache和mod_wsgi.为所有用户安装了Python.请帮帮我-
I am using 32 bit of Python,Apache and mod_wsgi. Python is installed for all user. Please help me -
推荐答案
首先在模块文件夹中复制mod_wgi,然后将以下内容添加到httpd.conf模块列表:
First of all copy mod_wgi in modules folder, then add following to httpd.conf modules list:
LoadModule wsgi_module modules/mod_wsgi.so
注意命名很重要(应在_module后缀)
attention that naming is important (should suffix with _module)
将以下内容添加到您的httpd.conf
Add the following to your httpd.conf
Include path_to_your_proj/django_wsgi.conf
django_wsgi.conf文件:
django_wsgi.conf file:
WSGIScriptAlias path_to/django.wsgi
<Directory project_path>
Allow from all
Order allow,deny
</Directory>
Alias /static path_to_static_files
django.wsgi文件:
django.wsgi file:
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()
如果您正在使用virtualenv(我建议),请执行以下操作:
httpd.conf文件:
httpd.conf file:
# 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文件:
wsgi.py file:
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()
这篇关于在Windows上为Wamp Server配置mod_wsgi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!