centos 6.4-使用 apache 和 mod_wsgi 部署 django

centos 6.4-使用 apache 和 mod_wsgi 部署 django

我正在尝试在装有 centos 6.4 的虚拟机上部署一个带有 apache 和 mod_wsgi 的基本 django 项目。这是项目树:

myproj/
├── manage.py
├── myapp
│   ├── __init__.py
│   ├── models.py
│   ├── tests.py
│   └── views.py
└── myproj
    ├── __init__.py
    ├── __init__.pyc
    ├── settings.py
    ├── settings.pyc
    ├── urls.py
    └── wsgi.py

这是 wsgi.py 文件(它是由 django-admin.py startproject 生成的默认文件):

"""
WSGI config for myproj project.

This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.

Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.

"""
import os

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "myproj.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproj.settings")

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)

这是虚拟主机配置(/etc/httpd/conf/httpd.conf):

#WSGIPythonPath /home/www/myproj/myproj
<VirtualHost *:82>
     ServerAdmin [email protected]
     WSGIScriptAlias /django /home/www/myproj/mypproj/wsgi.py
     WSGIDaemonProcess myproj user=apache threads=3
     <Directory />
        Options FollowSymLinks
        AllowOverride None
     </Directory>
     DocumentRoot /tmp
     ServerName www.example.com
     ServerAlias www.example.com
     ErrorLog /var/log/httpd/error_log
     CustomLog /var/log/httpd/access_log combined
</VirtualHost>

虽然我可以访问索引 Apache 页面(本地网络上的 192.168.0.15:80),但如果我尝试将浏览器指向 192.168.0.15:82,则会收到“目标无法访问”的提示。您知道配置中缺少什么或出了什么问题吗?在访问或错误日志中没有活动痕迹...


这是修改后的虚拟主机配置:

<VirtualHost *:82>
     ServerAdmin [email protected]
     WSGIScriptAlias /django /home/www/myproj/myproj/wsgi.py
     WSGIDaemonProcess myproj user=apache threads=3 python-path=/home/www/myproj/myproj/:/usr/lib/python2.6/site-packages
     WSGIProcessGroup myproj
     <Directory /home/www/myproj/myproj>
        <Files wsgi.py>
            Order allow,deny
            Allow from all
        </Files>
     </Directory>
     #DocumentRoot /tmp
     #ServerName www.example.com
     #ServerAlias www.example.com
     #Alias /media/ /home/www/myproj/
     ErrorLog /var/log/httpd/error_log
     CustomLog /var/log/httpd/access_log combined
</VirtualHost>

...什么都没变。开启:

wget 192.168.0.15:82

我收到“连接被拒绝”的消息。Debian 机器上的相同配置有效(在这种情况下映射到端口 80)。有什么帮助吗?

答案1

如果您想直接访问端口 82,则需要在服务器的防火墙中打开相应的端口。您可以使用system-config-firewall-tui命令行工具执行此操作。

相关内容