我正在尝试在我的RedHat服务器上部署我的本地Django项目。所以我安装了我需要的所有库和依赖项(也是mod_wsgi)。
因此,我编辑项目的设置并将我的本地项目移动到服务器。但是我遇到了一个问题:当我尝试访问项目的URL时,我有浏览器视图。
我还编辑了httpd.conf文件:
WSGIScriptAlias /var/www/html/virtualEnv/ /var/www/html/virtualEnv/ThirdPartyApplications/ThirdPartyApplications/wsgi.py
WSGIPythonPath /var/www/html/virtualEnv/ThirdPartyApplications/:/var/www/html/virtualEnv/lib/python2.7/site-packages
WSGIDaemonProcess http://licops.app.ale-international.com/ python-path=/var/www/html/virtualEnv/ThirdPartyApplications/:/var/www/html/virtualEnv/lib/python2.7/site-packages
WSGIProcessGroup http://licops.app.ale-international.com/
<Directory /var/www/html/virtualEnv/ThirdPartyApplications/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
编辑:@FlipperPA
到目前为止,我在/etc/httpd/conf.d/djangoproject.conf中运行此conf:
WSGISocketPrefix /var/run/wsgi
NameVirtualHost *:448
Listen 448
ServerName http://server.name-international.com
ErrorLog /home/myuser/apache_errors.log
WSGIDaemonProcess MyApp python-path=/var/www/html/MyApp:/var/www/html/MyApp/MyApp/lib/python2.7/site-packages
WSGIProcessGroup MyApp
WSGIScriptAlias /MyApp /home/user/MyApp/MyApp/wsgi.py
Alias /static /var/www/html/MyApp/MyApp/static
答案 0 :(得分:6)
这是我使用Apache 2.2在CentOS 6.8上运行的Apache配置示例;我将其命名为yourproject.conf
,并将其包含在/etc/httpd/conf.d
中,以便它包含在主Apache配置文件中:
LoadModule wsgi_module modules/mod_wsgi.so
LoadModule ssl_module modules/mod_ssl.so
WSGISocketPrefix /var/run/wsgi
NameVirtualHost *:443
Listen 443
<VirtualHost *:443>
ServerName yourservername.com
ErrorLog /home/yourusername/apache_errors.log
WSGIDaemonProcess yourproject-https python-home=/home/yourusername/.virtualenvs/yourproject
WSGIScriptAlias /yourproject /var/www/html/yourproject/yourproject/wsgi.py process-group=yourproject-https application-group=yourproject-https
WSGIProcessGroup yourproject-https
Alias /yourproject/static/ /var/www/html/yourproject/static/
SSLENGINE on
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLProtocol all -SSLv2
</VirtualHost>
您可能还需要调整Django项目中的wsgi.py
:
import os, sys
from django.core.wsgi import get_wsgi_application
sys.path.append(os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2]))
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yourproject.settings")
application = get_wsgi_application()
这假定您的virtualenv
位于/home/yourusername/.virtualenvs/yourproject
,而您的Django项目位于/var/www/html/yourproject
。它还会将Apache错误写入您的主目录,以防您遇到任何障碍。祝你好运!
答案 1 :(得分:2)
这是一个示例/etc/httpd/conf/httpd.conf
文件:
<VirtualHost *:80>
ServerName my.webapp.com
ServerAlias my.webapp.com
ErrorLog /var/www/my.webapp.com/error.log
WSGIDaemonProcess my.webapp.com \
python-path=/var/www/my.webapp.com/my-django-project:/home/me/virt-envs/md-env/local/lib/python2.7/site-packages
WSGIProcessGroup my.webapp.com
DocumentRoot /var/www/my.webapp.com/my-django-project
Alias /static/ /var/www/my.webapp.com/static/
WSGIScriptAlias / /var/www/my.webapp.com/my-django-project/my-django-project/wsgi.py \
process-group=my.webapp.com
<Directory /var/www/my.webapp.com/my-django-project>
Order allow,deny
Satisfy Any
Allow from all
Options ExecCGI
AddHandler wsgi-script .wsgi
</Directory>
<Directory /var/www/my.webapp.com/my-django-project/my-django-project>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
<Directory /var/www/my.webapp.com/static>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
另外wsgi.conf
:
LoadModule wsgi_module modules/mod_wsgi.so
然后是wsgi.py:
import os
import site
import sys
prev_sys_path = list(sys.path)
for directory in ALLDIRS:
site.addsitedir(directory)
new_sys_path = []
for item in list(sys.path):
if item not in prev_sys_path:
new_sys_path.append(item)
sys.path.remove(item)
sys.path[:0] = new_sys_path
sys.path.append('/var/www/my.webapp.com/my-django-project')
sys.path.append('/var/www/my.webapp.com/my-django-project/my-django-project')
from django.core.wsgi import get_wsgi_application
os.environ["DJANGO_SETTINGS_MODULE"] = "my-django-project.settings"
application = get_wsgi_application()