简体   繁体   English

403 禁止使用带有 WSGI 和 Apache2.4 的 flask 应用程序

[英]403 forbidden using a flask app with WSGI and Apache2.4

I'm trying to run a dash app on our website in a sub-directory.我正在尝试在我们网站的子目录中运行一个破折号应用程序。 I'm getting a 403 forbidden when trying to access to website.我在尝试访问网站时收到 403 禁止。 In the /etc/httpd/logs/ssl_error_logs i get the error:/etc/httpd/logs/ssl_error_logs我收到错误:

[Tue Jan 03 13:53:42.973046 2023] [autoindex:error] [pid 50576] [client 134.94.71.5:60550] AH01276: Cannot serve directory /var/www/Typesetter/appname/: No matching DirectoryIndex (index.html,index.php,index.php) found, and server-generated directory index forbidden by Options directive

I think i might have something wrong with either the permissions or the virtualhost setup.我想我的权限或虚拟主机设置可能有问题。 But i can't figure out what is going wrong.但我不知道出了什么问题。

I want to run the dashboard on: our-group.our-uni.com/appname我想在以下位置运行仪表板:our-group.our-uni.com/appname

The server is running on centos7.服务器在centos7上运行。

I got a data folder with biochemical information to provide to the users in /var/www/html/appname/data/ from which i can download the data if i go to our-group.our-uni.com/appname/data/datapoint1.pt .我有一个包含生化信息的数据文件夹,可以提供给/var/www/html/appname/data/中的用户,如果我 go 到our-group.our-uni.com/appname/data/datapoint1.pt ,我可以从中下载数据our-group.our-uni.com/appname/data/datapoint1.pt

Since this works and i can also put a index.html/index.php page there without issues, i think my virtualhost setup pointing to WSGI is incorrect?因为这有效,我也可以毫无问题地放一个 index.html/index.php 页面,我认为我的指向 WSGI 的虚拟主机设置不正确?

The error says cannot serve directory /var/www/Typesetter/appname/ , but this directory is a symbolic link to /var/www/html/appname/ .错误提示无法提供目录/var/www/Typesetter/appname/ ,但此目录是指向/var/www/html/appname/的符号链接。

The virtualhost file appname.conf located in /etc/httpd/conf.d/ :虚拟主机文件appname.conf位于/etc/httpd/conf.d/

<VirtualHost *:80>
        ServerName our-group.our-uni.com

        DocumentRoot /var/www/html/appname

        Errorlog /var/www/html/appname/appname-error.log

        Alias /topenzyme /var/www/html/topenzmye

        WSGIDaemonProcess appname user=apache group=apache threads=5 python-path=/var/www/html/appname/appname-env
        WSGIScriptAlias /appname /var/www/html/appname/testapp.wsgi

        <Directory /var/www/html/appname>
            WSGIProcessGroup appname
            WSGIApplicationGroup %{GLOBAL}
            Options Indexes FollowSymLinks ExecCGI
            Require all granted
        </Directory>
</VirtualHost>

I also tried changing to <Directory /var/www/typesetter/appname> , but this also did not work.我也尝试更改为<Directory /var/www/typesetter/appname> ,但这也没有用。

The contents of testapp.wsgi in /var/www/html/appname/ : /var/www/html/appname/testapp.wsgi的内容:

import sys, os
sys.path.insert(0, '/var/www/html/appname')
from testapp import app as application

The contents of testapp.py in /var/www/html/appname/ : /var/www/html/appname/testapp.py的内容:

from flask import Flask
app = Flask(__name__)

@app.route('/topenzyme/')
def main():
    return 'Hello world'

if __name__ == '__main__':
    app.run()

Permission setup:权限设置:

-rwxr-xr-x.  1 apache    apache      148 Jan  3 13:37 testapp.py
-rwxr-xr-x.  1 apache    apache      100 Jan  3 13:38 testapp.wsgi

I also tried 777, but from what i've read 755 permissions should be sufficient?我也试过 777,但据我所知,755 权限应该足够了吗?

If i do httpd -M i get wsgi_module (shared) .如果我做httpd -M我得到wsgi_module (shared) The wsgi module should be available. wsgi 模块应该可用。

I tried various virtualhost configs from other posts with similar issues.我尝试了其他具有类似问题的帖子中的各种虚拟主机配置。

I'm really unsure why this is not working.我真的不确定为什么这不起作用。

Is there anything wrong with my configuration settings or could it be something else?我的配置设置有什么问题还是其他原因?

Found out the issue.发现了问题。 I was miss-configuring my Apache setup.我错误地配置了我的 Apache 设置。

As we are already hosting a website on the domain, i should not have tried to setup a virtualhost for the sub-directory.因为我们已经在域上托管了一个网站,所以我不应该尝试为子目录设置虚拟主机。 From what i understand now this only works for setting up (sub)domains.据我所知,这仅适用于设置(子)域。 With this structure of setting it up the appname.conf file gets added the already existing virtualhost config.通过这种设置结构,appname.conf 文件被添加到已经存在的虚拟主机配置中。

Instead the /etc/httpd/conf.d/appname.conf is now:相反/etc/httpd/conf.d/appname.conf现在是:

WSGIDaemonProcess appname user=apache group=apache threads=5 python-path=/var/www/html/appname/appnameenv
WSGIProcessGroup appname 
WSGIApplicationGroup %{GLOBAL}
WSGIScriptAlias /appname /var/www/html/appname/testapp.wsgi

<Directory /var/www/html/appname>
        Options FollowSymLinks
        AllowOverride  All
        Require all granted
        allow from all
</Directory>

This corrently links the wsgi application to my sub-directory location i wanted (our-group.our-uni.com/appname)这将 wsgi 应用程序正确地链接到我想要的子目录位置(our-group.our-uni.com/appname)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM