使用ec2 amazon和httpd进行烧瓶部署

时间:2023-01-26 12:18:45

I want to deploy my flask application (who runs perfectly on localhost) , in an amazon EC2 server

我想在亚马逊EC2服务器上部署我的烧瓶应用程序(在localhost上运行完美)

this is my /etc/httpd/conf.d/wsgi.conf:

这是我的/etc/httpd/conf.d/wsgi.conf:

LoadModule wsgi_module modules/mod_wsgi.so


<VirtualHost *:80>
    ServerName ec2-52-17-211-242.eu-west-1.compute.amazonaws.com/
    ServerAdmin  webmaster@dummy-host.example.com
    WSGIScriptAlias / /opt/i01/var/www/FlaskApp/flaskapp.wsgi
    <Directory /opt/i01/var/www/FlaskApp/FlaskApp/>
        Order allow,deny
        Allow from all
    </Directory>
    Alias /static /opt/i01/var/www/FlaskApp/FlaskApp/static
    <Directory /opt/i01/var/www/FlaskApp/FlaskApp/static/>
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog logs/i01.io-error_log
    CustomLog logs/i01.io-access_log common

</VirtualHost>

the flaskapp.wsgi:

import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/opt/i01/var/www/FlaskApp/")

from FlaskApp import app as application
application.secret_key = 'Add your secret key'

and my __init__.py:

和我的__init__.py:

from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
    return "Hello, I love Digital Ocean!"
if __name__ == "__main__":
    app.run()

I have a configuration problem , but I don't found it

我有配置问题,但我没有找到它

2 个解决方案

#1


thank you for your answer , I fixed my problem the problem was just the WSGIPythonPath that wasn't defined

谢谢你的回答,我解决了我的问题,问题只是未定义的WSGIPythonPath

so I just added this line and it worked

所以我刚添加了这一行并且它有效

WSGIPythonPath /opt/i01/var/www/FlaskApp/FlaskApp/venv/:/opt/i01/var/www/FlaskApp/FlaskApp/venv/lib/python2.7/site-packages

#2


Your server name shouldn't have a trailing slash (ServerName ec2-52-17-211-242.eu-west-1.compute.amazonaws.com/). It MUST not have a trailing slash if you are using name-based virtual hosts, because your browser's request won't be mapped to that VirtualHost.

您的服务器名称不应具有斜杠(ServerName ec2-52-17-211-242.eu-west-1.compute.amazonaws.com/)。如果使用基于名称的虚拟主机,则它必须没有尾部斜杠,因为浏览器的请求不会映射到该VirtualHost。

Typically with mod_wsgi you'll set python-path to the site-packages directory of your virtualenv (if you have one).

通常使用mod_wsgi,您可以将python-path设置为virtualenv的site-packages目录(如果有的话)。

(But you need to show any error log messages when you try to hit that vhost -- or say that there aren't any -- and indicate what response your browser gets. You should be able to test locally with a symlink from /opt/i01/var/www/ to your real directory. I'd add that in a comment but I have no karma to do so.)

(但是当你试图点击那个vhost时你需要显示任何错误日志消息 - 或者说没有任何错误日志消息 - 并指出你的浏览器得到了什么响应。你应该能够使用来自/ opt的符号链接进行本地测试/ i01 / var / www /到您的真实目录。我会在评论中添加它,但我没有业力。)

#1


thank you for your answer , I fixed my problem the problem was just the WSGIPythonPath that wasn't defined

谢谢你的回答,我解决了我的问题,问题只是未定义的WSGIPythonPath

so I just added this line and it worked

所以我刚添加了这一行并且它有效

WSGIPythonPath /opt/i01/var/www/FlaskApp/FlaskApp/venv/:/opt/i01/var/www/FlaskApp/FlaskApp/venv/lib/python2.7/site-packages

#2


Your server name shouldn't have a trailing slash (ServerName ec2-52-17-211-242.eu-west-1.compute.amazonaws.com/). It MUST not have a trailing slash if you are using name-based virtual hosts, because your browser's request won't be mapped to that VirtualHost.

您的服务器名称不应具有斜杠(ServerName ec2-52-17-211-242.eu-west-1.compute.amazonaws.com/)。如果使用基于名称的虚拟主机,则它必须没有尾部斜杠,因为浏览器的请求不会映射到该VirtualHost。

Typically with mod_wsgi you'll set python-path to the site-packages directory of your virtualenv (if you have one).

通常使用mod_wsgi,您可以将python-path设置为virtualenv的site-packages目录(如果有的话)。

(But you need to show any error log messages when you try to hit that vhost -- or say that there aren't any -- and indicate what response your browser gets. You should be able to test locally with a symlink from /opt/i01/var/www/ to your real directory. I'd add that in a comment but I have no karma to do so.)

(但是当你试图点击那个vhost时你需要显示任何错误日志消息 - 或者说没有任何错误日志消息 - 并指出你的浏览器得到了什么响应。你应该能够使用来自/ opt的符号链接进行本地测试/ i01 / var / www /到您的真实目录。我会在评论中添加它,但我没有业力。)