简体   繁体   中英

403 when trying to deploy Flask app on GoDaddy

I'm getting a 403: Forbidden error when trying to deploy a test Flask app on GoDaddy. I've installed Python 3.5.7, and the files I've added/changed are:

1) created .htaccess in public_html:

Options +ExecCGI
AddHandler cgi-script .py
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /home/myusername/public_html/python/cgi-bin/app.cgi/$1 [L]

2) created a virtual environment venv in cgi-bin and installed Flask

3) created app.cgi in public_html/cgi-bin:

#!/home/myusername/.local/bin/python3
import os
import sys
sys.path.insert(0, '/home/myusername/public_html/cgi-bin/venv/lib/python3.5/site-packages')
from wsgiref.handlers import CGIHandler
activate_this = '/home/myusername/public_html/cgi_bin/venv/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from app import app
class ProxyFix(object):
    def __init__(self, app):
        self.app = app
    def __call__(self, environ, start_response):
        environ['SERVER_NAME'] = ""
        environ['SERVER_PORT'] = "80"
        environ['REQUEST_METHOD'] = "GET"
        environ['SCRIPT_NAME'] = ""
        environ['QUERY_STRING'] = ""
        environ['SERVER_PROTOCOL'] = "HTTP/1.1"
        return self.app(environ, start_response)
if __name__ == '__main__':
    app.wsgi_app = ProxyFix(app.wsgi_app)
    CGIHandler().run(app)
app.wsgi_app = ProxyFix(app.wsgi_app)
CGIHandler.run(app)

4) created app.py in public_html/cgi-bin:

from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
    return render_template('home.html')
if __name__ == '__main__':
    app.run()

5) created home.html in public_html/cgi-bin/templates

I've also modified the permissions to 755 for these various files.

Does anyone have any suggestions for where I might be going wrong? Thanks so much for any guidance.

RewriteRule /home/myusername/public_html/python/cgi-bin/app.cgi/$1 [L]

You are missing the pattern (first) argument to the RewriteRule directive - so this isn't doing anything. You should also be rewritting to a URL-path, not an absolute filesystem path. So, this should be something like the following instead:

RewriteRule !^python/cgi-bin/app.cgi/ /python/cgi-bin/app.cgi%{REQUEST_URI} [L]

Assuming /public_html is the document root directory.

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