首页 > 解决方案 > 如何配置 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 但我不知道我需要更改什么,因为文章中只有那个。谢谢

标签: pythondjangoapache.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

推荐阅读