Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VPS上以生产模式在Ubuntu 16.04 LTS上的NginX/Passenger服务器上部署Flask应用程序_Nginx_Flask_Ubuntu 16.04_Passenger_Vps - Fatal编程技术网

在VPS上以生产模式在Ubuntu 16.04 LTS上的NginX/Passenger服务器上部署Flask应用程序

在VPS上以生产模式在Ubuntu 16.04 LTS上的NginX/Passenger服务器上部署Flask应用程序,nginx,flask,ubuntu-16.04,passenger,vps,Nginx,Flask,Ubuntu 16.04,Passenger,Vps,问题1:问题出在哪里?: 接下来,我在Ubuntu 16.04上安装了Nginx和Passenger来运行PythonFlask应用程序,我遇到了这个问题:当我在浏览器中访问我的服务器时,我收到了以下错误: 很抱歉,出了点问题 问题2:乘客版本和集成模式: 乘客开源6.0.4+Nginx 问题3:操作系统或Linux发行版,平台(包括版本): Ubuntu 16.04 LTS $ uname -a Linux hXXXXXXX.stratoserver.net 4.4.0-042stab141.

问题1:问题出在哪里?: 接下来,我在Ubuntu 16.04上安装了
Nginx
Passenger
来运行Python
Flask
应用程序,我遇到了这个问题:当我在浏览器中访问我的服务器时,我收到了以下错误:

很抱歉,出了点问题

问题2:乘客版本和集成模式: 乘客开源6.0.4+Nginx

问题3:操作系统或Linux发行版,平台(包括版本): Ubuntu 16.04 LTS

$ uname -a
Linux hXXXXXXX.stratoserver.net 4.4.0-042stab141.3 #1 SMP Fri Nov 15 22:45:34 MSK 2019 x86_64 x86_64 x86_64 GNU/Linux
问题4:乘客安装方法: Nginx+Phusion APT回购

问题5:你的应用程序的编程语言: Python 3.7.6+烧瓶1.1.1

问题6:您是否使用PaaS和/或集装箱运输?如果是,哪一个? 没有

问题7:关于您的设置,我们还需要知道什么吗? 我在strato.nl安装了一个VPS,安装了Ubuntu 16.04,主机地址是:在教程中,我在“部署一个Python应用程序,将乘客带到生产环境”中做了以下选择:

1. Linux/Unix
2. Nginx
3. Passenger open source
4. Python installed via LinuxBrew (Python v3.7.6)
5. Ubuntu 16.04 LTS
6. Demo Flask app from github
demo Flask应用程序是从Phusio客运github克隆的,如下所示:

git clone https://github.com/phusion/passenger-python-flask-demo.git
运行
乘客记忆统计信息
可提供:

$ sudo /usr/sbin/passenger-memory-stats
Version: 6.0.4
Date   : 2020-01-29 13:12:15 +0100
------------- Apache processes -------------
*** WARNING: The Apache executable cannot be found.
Please set the APXS2 environment variable to your 'apxs2' executable's filename, or set the HTTPD environment variable to your 'httpd' or 'apache2' executable's filename.


---------- Nginx processes -----------
PID    PPID   VMSize    Private  Name
--------------------------------------
23320  1      174.9 MB  0.8 MB   nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
23325  23320  174.9 MB  0.8 MB   nginx: worker process
### Processes: 2
### Total private dirty RSS: 1.54 MB


----- Passenger processes -----
PID    VMSize    Private  Name
-------------------------------
23309  445.7 MB  2.5 MB   Passenger watchdog
23312  672.3 MB  7.5 MB   Passenger core
### Processes: 2
### Total private dirty RSS: 9.98 MB
当我在服务器上本地运行应用程序时,一切正常:

$ python app.py
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
然后在另一个终端:

$ curl localhost:5000
<!DOCTYPE html>
<html>
<head>
  <title>Hello</title>
  <style>
    html, body {
      font-family: sans-serif;
      background: #f0f0f0;
      margin: 4em;
    }

    .main {
      background: white;
      border: solid 1px #c0c0c0;
      border-radius: 8px;
      padding: 2em;
    }
  </style>
</head>
<body>

  <section class="main">
    <h1>Hello world!</h1>
    <p>Welcome to the Passenger Flask example app.</p>
  </section>

</body>
</html>
因此,脚本似乎找不到我以前为Python3安装的包,它使用的是Python2包。在服务器响应中打印
sys.version
,将给出:

sys.version: 2.7.17 (default, Dec 24 2019, 17:49:09)
我为Python3安装了所有软件包,因此需要在使用Python3的服务器上安装脚本如何在NginX/Passenger中设置Python版本和Python库?

我的demoapp配置是:

$ vi /etc/nginx/sites-enabled/demoapp.conf
server {
    listen 80;
    server_name hXXXXXXX.stratoserver.net;

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/demoapp/code/public;

    # Turn on Passenger
    passenger_enabled on;
}
要成功运行Flask应用程序,我需要设置哪些乘客/Nginx设置?
如何将Passenger/Nginx设置为使用Python3和Python3站点包?

解决方案是在应用程序的配置文件(在服务器上下文中)中添加Python二进制文件的路径。现在,我的配置文件demoapp.conf如下所示:

$ vi /etc/nginx/sites-enabled/demoapp.conf
server {
    listen 80;
    server_name hXXXXXXX.stratoserver.net;

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/demoapp/code/public;

    # Tell Nginx and Passenger which Python executable to use
    passenger_python /home/linuxbrew/.linuxbrew/bin/python3;

    # Turn on Passenger
    passenger_enabled on;
}
一切都按预期进行。请注意这一行:

passenger_python /home/linuxbrew/.linuxbrew/bin/python3;
它指向与linuxbrew一起安装的Python v3.7.6二进制文件。

另一个选项是使用Python虚拟环境,您还可以在其中指定要使用的Python版本

passenger_python /home/linuxbrew/.linuxbrew/bin/python3;