현재 Amazon의 AWS에서 호스팅되는 Flask 응용 프로그램을 작성 중입니다. 내가 작업하고있는 응용 프로그램에는 몇 가지 구성 요소가 있으며 그 중 두 가지를 작업하고 있습니다. 몇 가지 문제가 있음에도 불구하고이 구성 요소의 하위 도메인을 설정하려고합니다.플라스크 SERVER_NAME은 결코 수정되지 않습니다
내가 원하는 :
- www.example.com>에서 GoDaddy에게
- dashboard.example.com> AWS를
- api.example.com> AWS
가 www
하위 도메인은 정적 인 사이트와 그 모든 것이 잘 진행되고 있습니다. dashboard.example.com과 api.example.com이 내 Flask 응용 프로그램을 실행하는 EC2 서버에 도달하도록 Route53 및 GoDaddy를 설정할 수있었습니다. 브라우저에서 도메인을 방문했을 때 요청 (404ing)을 볼 수 있기 때문에이를 확인했습니다.
내가 가지고있는 문제는 Flask가 app.config.SERVER_NAME
이 URI와 일치해야하는 서버 이름으로 설정 될 것으로 예상한다는 것입니다. 내 EC2 인스턴스의 서버 이름은 ec2-###-###-###-###.compute-1.amazonaws.com.
입니다. 내 서버 이름을 이렇게 설정하면 Flask 응용 프로그램이 정상적으로 실행되고 404 페이지가 표시되고 Flask 응용 프로그램의 출력을 볼 때 요청을 볼 수 있습니다. dashboard.example.com 또는 api.example.com 중 하나로 이동하십시오.
from flask import \
Flask, \
request
# my imports
from dashboard import blueprint as dashboard
app = Flask(__name__)
@app.route('/')
def catch():
return request.url
def main():
print('Starting main ...')
app.register_blueprint(dashboard)
if __name__ == '__main__':
main()
app.config['SERVER_NAME'] = 'example.com'
app.run(
host=app.config['server_name'],
port=80,
debug=True,
)
:
내가이 플라스크 응용 프로그램이 실행되지 않을 경우 비록 app.config.SERVER_NAME
이 example.com으로 설정해야합니다 404 페이지를 표시하지 않으려면, 내가 여기
socket.error: [Errno 99] Cannot assign requested address.
을 얻을 나의 코드
여기 내 대시 보드 모듈은 다음과 같습니다.
from flask import \
render_template, \
Blueprint,\
Response
blueprint = Blueprint(
'dashboard', __name__,
static_folder='static',
template_folder='templates',
subdomain='dashboard',)
@blueprint.route('/', methods=['GET'])
def _():
return render_template('index.html')
@blueprint.route('/js/')
def _js(path):
print('js : %s' % path)
with blueprint.open_resource('static/js/' + path, mode='r') as f:
content = f.read()
return Response(content, mimetype='text/javascript')
@blueprint.route('/css/')
def _css(path):
print('css : %s' % path)
with blueprint.open_resource('static/css/' + path, mode='r') as f:
content = f.read()
return Response(content, mimetype='text/css')
제공되는 도움말에 대해 미리 감사드립니다.
오타가 수정되었습니다. 그것을 잡아 주셔서 감사합니다. – Dawson