乘客苏里 [英] Passenger sub uri's

查看:100
本文介绍了乘客苏里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在大多数方面,Phusion乘客说明都很棒.他们在设置NGINX,乘客应用程序,测试python等方面的安装指南要好于平均水平.在单个服务器上设置几个单独的应用程序的说明很不完善.我采用乘客"的主要原因是能够托管多个应用程序.

The Phusion Passenger instructions are great in most regards. They have far better-than-average install guides on setting up NGINX, the passenger app, testing python, and so forth. The instructions on setting up several separate apps on a single server are, well, deficient. The main reason I adopted Passenger is the ability to host several apps.

我按照Phusion Passenger的说明使用子URI设置了NGINX服务器(

I followed the Phusion Passenger instructions for setting up NGINX server with a sub URI (https://www.phusionpassenger.com/library/deploy/nginx/deploy/python/). I thought this would allow me to run separate apps with different sub folders. I have several python applications in /var/www, like so:

/var/www/dashboard
/var/www/peniso

在单独的子文件夹venv中,我每个人都有一个Python虚拟环境.每个人都单独工作.但是,如何一次使所有内容可用?我看到的问题是,无论使用哪个子URI,同一应用程序都可以运行.

I have a Python virtual environment for each one, in the separate subfolders venv. Each one works individually. But how to make all available at once? The problem I see is that no matter which sub URI is used, the same app runs.

这是我在/etc/nginx/sites-enable/dashboard.conf文件中尝试过的内容:

Here's what I tried in my /etc/nginx/sites-enable/dashboard.conf file:

server {
    listen 80;
    server_name testapp.myexample.com;

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

    passenger_app_type wsgi;
    passenger_startup_file passenger_wsgi.py;

    # Turn on Passenger
    passenger_enabled on;
    passenger_python /var/www/dashboard/venv/bin/python3.7;

    location ~ ^/mydash(/.*|$) {
        alias /var/www/dashboard/public$1;
        passenger_base_uri /mydash;
        passenger_app_root /var/www/dashboard;
        passenger_document_root /var/www/dashboard/public;
        passenger_enabled on;
        passenger_python /var/www/dashboard/venv/bin/python3.7;
   }


   location ~ ^/efergy(/.*|$) {
        alias /var/www/peniso/public$1;
        passenger_base_uri /efergy;
        passenger_app_root /var/www/peniso;
        passenger_document_root /var/www/peniso/public;
        passenger_enabled on;
        passenger_app_env development;
        passenger_python /var/www/peniso/venv/bin/python3.7;
   }
}

我浏览http://testapp.myexample.com/mydashhttp://testapp.myexample.com/efergy,我看到的是显示的是同一应用程序.在顶部,在各小节之前,我可以将"dashboard"替换为"peniso",并更改运行1个应用程序的位置.我已经翻转了文件夹的顺序,也将根目录从一个更改为另一个.似乎只有一个应用可用.

I browse http://testapp.myexample.com/mydash or http://testapp.myexample.com/efergy I see is the same app showing. In the top part, before the sub-sections, I can replace "dashboard" with "peniso" and it changes which 1 app runs. I've flipped the ordering of the folders, also changed the root from one to the other. Still only one app seems to be available.

您如何配置乘客"以与几个不同的应用程序一起使用?

How do you configure Passenger to work with several different apps?

最终,一旦我了解了如何使/var/www下的目录正常工作,就需要托管一些Python和一些Node.js应用程序.

Eventually, I need to host some Python and some Node.js apps, once I understand how to get the directories under /var/www to work right.

推荐答案

我有一个特定于Python Ploty仪表板的解决方案,该仪表板使用称为Dash的抽象层编写.我希望可以为所有Plotly应用找到类似的修复程序,但是没有实现.可以修改Dash Plotly应用程序以了解通话的suburi.如果Web URL为http://example.com/energy,则在Plotly应用程序中需要进行简单的更改.

I have a solution that is specific to Python Ploty dashboard written with the abstraction layer called Dash. I expect similar fix can be found for all Plotly apps, but did not implement it. The Dash Plotly app can be modified to understand the suburi of the call. If the web URL is http://example.com/energy, then inside the Plotly app a simple change is needed.

从标准标准部分开始:

app = dash.Dash(__name__,
    meta_tags=[
        {
            "name": "viewport",
            "content": "width=device-width"
        }
    ]
)

包括网址的最后一部分

app = dash.Dash(__name__,
    meta_tags=[
        {
            "name": "viewport",
            "content": "width=device-width"
        }
    ],
    requests_pathname_prefix='/energy/'
)
app.config.suppress_callback_exceptions = True

最后一行是我在"Plotly"列表中同时拾取的东西,我不知道它是否至关重要.

The last line there is something I picked up in the Plotly list at the same time, I do not know if it is vital.

在旅客文档中,我发现sub-uri问题对于除Rails以外的所有其他应用程序都非常严重,因为Rails拥有纯乘客解决方案.整个事情没有得到很好的记录.但是它们在node.js文档中确实有警告( https://www.phusionpassenger.com/library/deploy/nginx/deploy/nodejs/):

In the Passenger documentation, I've discovered that the sub-uri problem is serious for all kinds of apps except Rails, where they have a pure-passenger solution. The whole thing is not very well documented. But they do have a warning in the node.js documents (https://www.phusionpassenger.com/library/deploy/nginx/deploy/nodejs/):

Sub-URI deployments in Node.js require framework-specific 
adjustments in the application. For example, in Express 4.0+, 
you should use a router. An alternative is to use url 
rewriting to avoid the need for sub-URIs altogether. 

在乘客GitHub"问题列表中,我创建了一个有关"URL重写的使用"的文档详细信息的请求,因为在大多数情况下,这是唯一切实可行的答案(

In the Passenger GitHub issue list, I created a request for documentation details on the "use of url rewriting" because that appears the only truly feasible answer in most cases (https://github.com/phusion/passenger/issues/2254). It is not workable for me to figure out case-specific fixes for every different node.js app that we want to run.

为了让每个人都了解这种情况,Passenger框架结构确实可以将服务器引导到正确的文件夹,但是当实际执行该应用程序时,nginx&乘客,出于我不了解的原因,恢复运行他们在配置文件中找到的第一个应用程序.修复此问题后,每个应用程序都知道如何调用该方法(也许nginx会读取其公告?),然后此方法就可以了.

Just so everybody understands the situation, the Passenger framework structure does work to guide the server to the correct folder, but when it comes time to actually execute the app, nginx & Passenger, for reasons I don't understand, revert to run the first app they find in the configuration file. As soon as you fix this so each app knows how to be called--maybe nginx reads their announcements??--then this does work.

这篇关于乘客苏里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆