gpt4 book ai didi

python - 在 RedHat 上部署 Django 项目

转载 作者:太空狗 更新时间:2023-10-30 00:48:42 25 4
gpt4 key购买 nike

我正在尝试在我的 RedHat 服务器上部署我的本地 Django 项目。所以我安装了我需要的所有库和依赖项(还有 mod_wsgi)。

因此,我编辑项目设置并将本地项目移至服务器。但我遇到了一个问题:当我尝试访问项目的 URL 时,我看到的是资源管理器 View 。

我还编辑了 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

最佳答案

这是我在 CentOS 6.8 和 Apache 2.2 上的 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/你的项目。它还会将 Apache 错误写入您的主目录,以防您遇到任何障碍。祝你好运!

关于python - 在 RedHat 上部署 Django 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37588417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com