python - 如何配置 Index.fcgi 路径?
问题描述
我正在使用 ssh 在我的主机上设置我的 Django 项目。我正在关注一篇文章以便能够正确安装它。我必须遵循的一些步骤如下:
创建 . htaccess 文件,其中包含 FCGI 处理程序的设置并重定向到将创建的 index.fcgi 文件:
AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.fcgi/$1 [QSA,L]
并使用以下内容在应用程序的根目录中创建 index.fcgi 文件:
#!/home/CONTA/.virtualenv/bin/python
import os, sys
from flup.server.fcgi import WSGIServer
from django.core.wsgi import get_wsgi_application
sys.path.insert(0, "/home/CUENTA/mydjango")
os.environ['DJANGO_SETTINGS_MODULE'] = "mydjango.settings"
WSGIServer(get_wsgi_application()).run()
已经在公共 html 中拥有这两个文件并使用chmod 0755选择对 index.fcgi 的权限当时我使用以下命令查看它是否正在运行./index.fcgi,告诉我没有文件或目录.
这让我假设我需要在 index.fcgi 或 . htaccess 但我不知道我需要更改什么,因为文章中只有那个。谢谢
解决方案
第 1 步:在项目文件夹中设置一个 .htaccess 文件,其中包含以下条目:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.fcgi/$1 [QSA,L]
第 2 步:使用以下代码在项目文件夹中设置一个 index.fcgi 文件(它将作为对 CMS 的所有请求的入口点)。不要忘记将“mydjangocms”替换为您的项目名称:
#!/home/venv/bin/python3.5
# -*- coding: utf-8 -*-
import os
import sys
activate_this = '/home/venv/bin/activate_this.py'
exec(open(activate_this).read(), dict(__file__=activate_this))
cms_path = '/home/www/mydjangocms/'
sys.path.insert(0, cms_path)
os.chdir(cms_path)
# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "mydjangocms.settings"
from django_fastcgi.servers.fastcgi import runfastcgi
from django.core.servers.basehttp import get_internal_wsgi_application
wsgi_application = get_internal_wsgi_application()
runfastcgi(wsgi_application, method="prefork", daemonize="false", minspare=1, maxspare=1, maxchildren=1)
第 3 步:您需要使用以下命令使 index.fcgi 文件可执行:
chmod +x index.fcgi
推荐阅读
- javascript - 使html中的脚本自动运行?
- java - 无限期地播放正弦波 - java
- python - 在一行中加入多个列表,不带括号或引号
- python - 使用反斜杠转义字符串中的单引号
- c# - 使用 Moq 设置 Mock 存储库
- sql - SQL 相关性和/或别名
- python - 查找并替换以小写开头的正确句子 case 句子。正则表达式或崇高
- ios - 为什么我以前的 viewController 中的变量不会显示在我的 labelText 中
- kubernetes - helm init '目标机器主动拒绝' 错误
- javascript - v-show 在我的代码中没有像我预期的那样工作