【问题标题】:Running multiple flask application on apache server在 apache 服务器上运行多个烧瓶应用程序
【发布时间】:2019-04-13 07:58:29
【问题描述】:

我在var/www/html 有多个烧瓶应用程序,例如var/www/html/websitevar/www/html/summaryvar/www/html/sentiment

一旦我成功运行所有应用程序。

然后我又添加了一个应用程序,我为其创建了 conf 文件并重新启动了服务器。

之后所有应用程序停止工作,只有var/www/html/sentiment 打开。

我在 python、wsgi 和 conf 文件中检查了其他应用程序的代码是否与情感相同。

情感应用代码

flaskapp.py

from flask import Flask
app = Flask(__name__)

@app.route('/sentiment')
def hello_world():
  return 'Hello from Sentiment!'

if __name__ == '__main__':
  app.run()


flaskapp.wsgi

import sys
sys.path.insert(0, '/var/www/html/sentiment/')

from flaskapp import app as application

conf 文件 - /etc/apache2/sites-available/sentiment.conf

<VirtualHost *:80>
                ServerName IP
                ServerAdmin admin@mywebsite.com
                WSGIScriptAlias / /var/www/html/sentiment/flaskapp.wsgi
                <Directory /var/www/html/sentiment/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

摘要应用程序代码 flaskapp.y

from flask import Flask
app = Flask(__name__)

@app.route('/summary')
def hello_world():
  return 'Hello from Summary!'

if __name__ == '__main__':
  app.run()

flaskapp.wsgi

import sys
sys.path.insert(0, '/var/www/html/summary/')

from flaskapp import app as application

/etc/apache2/sites-available/summary.conf

<VirtualHost *:80>
                ServerName IP
                ServerAdmin admin@mywebsite.com
                WSGIScriptAlias / /var/www/html/summary/flaskapp.wsgi
                <Directory /var/www/html/summary/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog ${APACHE_LOG_DIR}/error.log
                LogLevel warn
                CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

当我打开 ip/sentiment 时它仍然有效,但 ip/summary 给出了

The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

对此有何建议?

【问题讨论】:

  • 您的应用程序在同一个端口上运行,您是否尝试为app.run(port=xxxx) 中的每个应用程序更改端口?
  • 是的,我尝试在 app.run() 中提供不同的端口,但仍然是同样的问题。一次只运行一个应用程序
  • 但是,当您使用 &lt;VirtualHost *:80&gt; 时,您似乎正在覆盖应用程序的默认端口。这意味着您所有的应用程序都在端口 80 上运行。您是否尝试过配置文件中的不同端口?
  • 是的,但请给出一些不同的端口示例
  • 尝试从 5005 到 5010 的端口,以避免与您可能已经运行的任何内容发生冲突。您可以像这样配置每个实例:&lt;VirtualHost *:5005&gt; 等等……

标签: python apache flask


【解决方案1】:

问题在于您的 WSGIScriptAlias 名称。

/ 指向目录中的所有内容。

为所有应用程序提供唯一的别名。

示例:

WSGIScriptAlias

/ 更改为 /app1

WSGIScriptAlias/ 更改为 /app2

在这两个文件中。

然后重启服务器。

【讨论】:

    猜你喜欢
    • 2016-12-09
    • 1970-01-01
    • 2020-04-16
    • 2022-01-06
    • 2021-11-04
    • 1970-01-01
    • 2014-04-03
    • 2020-03-17
    • 1970-01-01
    相关资源
    最近更新 更多