简体   繁体   中英

Getting 403 forbidden while running flask app on apache(centos 7)

I have written a flask rest API which is working fine while executing using the command sudo python main.py . I wanted to configure that in apache and below are what I have done.

File structure /home/user/project_name/src/restApi/ :

- __init__.py
- main.py
- app.py
- service.wsgi

Here is main.py :

from app import app

@app.route('/api/v1/fileupload', methods=['POST'])
@auth.login_required
def upload_file():
  // code


@auth.verify_password
def verify(username, password):
    if not (username and password):
        return False
    return USERNAME == username and PASSWORD == password

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80)

Here is my app.py :

from flask import Flask

app = Flask(__name__)
//some config

Here is my service.wsgi :

#!/usr/bin/python
import sys

sys.path.insert(3, "/home/user/project_name/src/restApi/")
from app import app as application

Here is /etc/httpd/config/httpd.config

<VirtualHost *:80>
    ServerName 34.73.243.234
    DocumentRoot /home/user/project_name/src/restApi/
    WSGIScriptAlias /api/v1/fileupload /home/user/project_name/src/restApi/service.wsgi
    <Directory /home/user/project_name/src/restApi/>
        Order allow,deny
        Allow from all
    </Directory>

</VirtualHost>

Apologies, if I haven't explained very well. Well, when I am running main.py using the command sudo python main.py that time I am able to upload the file. But after configured apache and hitting the same URL getting a response as 403 forbidden You don't have permission to access /api/v1/fileupload on this server.

Please help me out. I've tried all the solutions, couldn't end up to fix the bug. Thanks

In

/etc/httpd/config/httpd.config

You have standing DocumentRoot, I mean this should be commented

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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