我有一个奇怪的烧瓶问题。我有一个运行在VM上的端口5000上的简单应用程序。我有一个config.py
文件,它正在设置侦听端口和IP。这是我的配置:
class BaseConfig(object):
DEBUG = False
TESTING = False
SECRET_KEY = 'my_secret_key_which_is_not_so_secret'
SERVER_NAME = '0.0.0.0:5000'
class DevConfig(BaseConfig):
DEBUG = True
TESTING = True
class TestConfig(BaseConfig):
DEBUG = False
TESTING = True
我还在__init__.py
文件中添加了以下行:app.config.from_object('config.DevConfig')
。当我启动应用程序时,这是日志:
$ python app.py
* Serving Flask app "webapp" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: XXX-XXX-XXX
/home/ubuntu/programming/lib/python3.6/site-packages/flask/sessions.py:217: UserWarning: The session cookie domain is an IP address. This may not work as intended in some browsers. Add an entry to your hosts file, for example "localhost.localdomain", and use that instead.
'The session cookie domain is an IP address. This may not work'
my.ip.add.ress - - [04/Dec/2018 10:09:16] "GET / HTTP/1.1" 404 -
my.ip.add.ress - - [04/Dec/2018 10:09:17] "GET /favicon.ico HTTP/1.1" 404 -
127.0.0.1 - - [04/Dec/2018 10:15:31] "GET / HTTP/1.1" 404 -
127.0.0.1 - - [04/Dec/2018 10:16:28] "GET /netemulator HTTerror 404 -
因此,当我尝试从PC上访问它时,会得到404错误,这与尝试使用elinks
内部访问它时遇到的错误相同。如果删除SERVER_NAME
中的config.py
行,我可以使用elinks
从VM内访问它,并且可以看到它已正确加载,但无法从PC上访问它。 。
$ python app.py
* Serving Flask app "webapp" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: XXX-XXX-XXX
127.0.0.1 - - [04/Dec/2018 10:18:34] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [04/Dec/2018 10:18:36] "GET /netemulator HTTP/1.1" 200 -