Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not able to mount applications in sub directories, but only sometimes #263

Closed
plockaby opened this issue May 3, 2013 · 11 comments
Closed

Comments

@plockaby
Copy link

plockaby commented May 3, 2013

This is related to this ticket, sort of: #242

Here's my PSGI file:

#!/usr/bin/env perl

use strict;
use warnings;
use Data::Dumper;

return sub {
    my $env = shift;
    return [
        '200',
        [ 'Content-Type' => 'text/html' ],
        [ "<h1>Hello World</h1><pre>" . Dumper($env) . "</pre>" ],
    ];
};

Here is my INI file:

[uwsgi]
chdir = /data/apps/test
psgi = index.psgi
http-socket = :3001
http-socket-modifier1 = 5
scgi-socket = :4001
scgi-modifier1 = 5
master = true
threads = 20
logto = /data/logs/uwsgi/test.log
plugins-dir = /data/sbin/uwsgi/plugins
plugins = psgi

Here is how I am starting uWSGI:

./uwsgi --emperor /data/conf/uwsgi/ --binary-path /data/sbin/uwsgi/bin/uwsgi

Here is the log from starting uWSGI:

*** Starting uWSGI 1.9.8 (64bit) on [Fri May  3 05:16:28 2013] ***
compiled with version: 4.4.5 on 02 May 2013 03:37:28
os: Linux-2.6.32-5-amd64 #1 SMP Mon Feb 25 00:26:11 UTC 2013
nodename: dev
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /data/sbin/uwsgi/bin
detected binary path: /data/sbin/uwsgi/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your memory page size is 4096 bytes
detected max file descriptor number: 1024
*** starting uWSGI Emperor ***
*** has_emperor mode detected (fd: 6) ***
[uWSGI] getting INI configuration from test.ini

Here is the log from the vassal:

*** Starting uWSGI 1.9.8 (64bit) on [Fri May  3 05:16:28 2013] ***
compiled with version: 4.4.5 on 02 May 2013 03:37:28
os: Linux-2.6.32-5-amd64 #1 SMP Mon Feb 25 00:26:11 UTC 2013
nodename: dev
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /data/conf/uwsgi
detected binary path: /data/sbin/uwsgi/bin/uwsgi
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to TCP address :3001 fd 3
uwsgi socket 1 bound to TCP address :4001 fd 4
initialized Perl 5.16.3 main interpreter at 0x11c5570
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 533888 bytes (521 KB) for 20 cores
*** Operational MODE: threaded ***
PSGI app 0 (index.psgi) loaded in 1 seconds at 0x14e0b00 (interpreter 0x11c5570)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 15175)
spawned uWSGI worker 1 (pid: 15176, cores: 20)

Seems all really standard. The root path of this server should respond to my PSGI script. When I connect via HTTP, everything works as expected. When I connect via PSGI, however, I get this error:

--- unable to find perl application ---
[pid: 15176|app: -1|req: -1/2] 192.168.2.1 () {62 vars in 1087 bytes} [Fri May  3 05:18:17 2013] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 56 bytes (0 switches on core 3)

If I change the configuration from this:

psgi=index.psgi

To this:

mount = /=index.psgi

Then when I connect via HTTP, I get this error:

--- unable to find perl application ---
[pid: 15208|app: -1|req: -1/2] 192.168.2.1 () {36 vars in 648 bytes} [Fri May  3 05:19:55 2013] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 3)

But when I connect via SCGI, now it works.

To summarize: when I use "index=psgi" it works with HTTP but not SCGI. When I use "mount=/=index.psgi" it works via SCGI but not HTTP.

@unbit
Copy link
Owner

unbit commented May 3, 2013

SCGI is variable based while HTTP is header based. Albeit both translates to the internal uwsgi format, handling SCRIPT_NAME accordingly is basically impossibile. I suppose your SCGI client is setting SCRIPT_NAME to /, so while in HTTP mode the "" app is searched, in SCGI mode it will search for "/". A good way to check it (without rebuilding in DEBUG mode) is adding this internal route:

route-run = log:SCRIPT_NAME=${SCRIPT_NAME}

to the uWSGI config.

You can bypass the problem forcing uWSGI to rewrite the SCRIPT_NAME with manage-script-name = true or to completely ignore it with ignore-script-name = true

Another approach would be introducing the default application concept in the psgi plugin. In the python and mono plugins the first loaded app is the default one. So unmatched SCRIPT_NAME/UWSGI_APPID fallback to it

@plockaby
Copy link
Author

plockaby commented May 3, 2013

Here is the output from HTTP, then SCGI, with the "mount" option enabled:

SCRIPT_NAME=/
[pid: 15391|app: 0|req: 2/3] 192.168.2.1 () {62 vars in 1087 bytes} [Fri May  3 05:49:39 2013] GET / => generated 2308 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 43 bytes (0 switches on core 2)
SCRIPT_NAME=
--- unable to find perl application ---
[pid: 15391|app: -1|req: -1/4] 192.168.2.1 () {36 vars in 648 bytes} [Fri May  3 05:49:40 2013] GET / => generated 21 bytes in 0 msecs (HTTP/1.1 500) 1 headers in 57 bytes (0 switches on core 2)

With the "mount" option, setting "manage-script-name = true" didn't change anything and setting "ignore-script-name = true" made it so that neither worked. :)

I suppose I should probably just choose either SCGI or HTTP and not both but I figured it would be nice to be able to debug without having to put Apache in front of uWSGI. However, there is still the problem that with "mount", HTTP does not work with PSGI. And with "psgi=foo", SCGI does not work with PSGI. (The opposite of how it was with #242.) And that's with independently of each other.

@unbit
Copy link
Owner

unbit commented May 3, 2013

The problem is that SCRIPT_NAME is different with the two approaches. Both should be empty (as suggested by CGI) but apache forces it to /. This is the main problem, for uWSGI/PSGI they are 2 different application. You can make this trick to force it to /:

--route-if = empty:${SCRIPT_NAME} setapp:/

basically it tells uWSGI to use the app mounted under / when the SCRIPT_NAME is empty

By the way i think i will add the default app concept to the psgi plugin later today, it is not obviously a fix but would mask the problem pretty well for single apps

@plockaby
Copy link
Author

plockaby commented May 3, 2013

Now that "route-if" option did the trick. Just set the path to whatever my "mount" option is and everything works the way I expect it to. Thanks! Hopefully this will migrate to the documentation at some point. :)

@plockaby plockaby closed this as completed May 3, 2013
@unbit
Copy link
Owner

unbit commented May 4, 2013

support for default app (only if the mountpoint is empty or /) has been added

@KES777
Copy link

KES777 commented Aug 24, 2015

In single APP environment all works fine

psgi = /home/user/public_html/my-app.psgi
manage-script-name = true
Mon Aug 24 13:05:19 2015 - *** Operational MODE: single process ***
2015/08/24 13:05:19 Application is started
Mon Aug 24 13:05:20 2015 - PSGI app 0 (/home/user/public_html/my-app.psgi) loaded in 1 seconds at 0x1b46f08
Mon Aug 24 13:05:20 2015 - spawned uWSGI master process (pid: 5810)
Mon Aug 24 13:05:20 2015 - spawned uWSGI worker 1 (pid: 5834, cores: 1)

But when trying to prepare to multiple apps

mount = ""=/home/user/public_html/my-app.psgi
manage-script-name = true

reloading server is OK

Mon Aug 24 13:08:26 2015 - *** Operational MODE: single process ***
Mon Aug 24 13:08:26 2015 - mounting /home/user/public_html/my-app.psgi on ""
2015/08/24 13:08:26 Application is started
Mon Aug 24 13:08:26 2015 - PSGI app 0 (/home/user/public_html/my-app.psgi) loaded in 0 seconds at 0x1e1d3d0 (inter
Mon Aug 24 13:08:26 2015 - spawned uWSGI master process (pid: 6002)
Mon Aug 24 13:08:26 2015 - spawned uWSGI worker 1 (pid: 6026, cores: 1)

but first request cause

Mon Aug 24 13:10:13 2015 - --- unable to find perl application ---

Trying two different configurations:

mount = "app"=/home/user/public_html/my-app.psgi
manage-script-name = true
Mon Aug 24 13:12:04 2015 - *** Operational MODE: single process ***
Mon Aug 24 13:12:04 2015 - mounting /home/user/public_html/my-app.psgi on "app"
2015/08/24 13:12:04 Application is started
Mon Aug 24 13:12:04 2015 - PSGI app 0 (/home/user/public_html/my-app.psgi) loaded in 0 seconds at 0x2e2d330 (inter
Mon Aug 24 13:12:04 2015 - spawned uWSGI master process (pid: 6193)
Mon Aug 24 13:12:04 2015 - spawned uWSGI worker 1 (pid: 6217, cores: 1)
Mon Aug 24 13:12:30 2015 - --- unable to find perl application ---

And second:

mount = "/"=/home/user/public_html/my-app.psgi
manage-script-name = true

Mon Aug 24 13:15:15 2015 - *** Operational MODE: single process ***
Mon Aug 24 13:15:15 2015 - mounting /home/user/public_html/my-app.psgi on "/"
2015/08/24 13:15:15 Application is started
Mon Aug 24 13:15:15 2015 - PSGI app 0 (/home/user/public_html/my-app.psgi) loaded in 0 seconds at 0x25a2d60 (inter
Mon Aug 24 13:15:15 2015 - spawned uWSGI master process (pid: 6369)
Mon Aug 24 13:15:15 2015 - spawned uWSGI worker 1 (pid: 6393, cores: 1)

Gives same result:

--- unable to find perl application ---

@unbit
Copy link
Owner

unbit commented Aug 24, 2015

Can you remove double quotes ? They will be included in the mountpoint

@KES777
Copy link

KES777 commented Aug 24, 2015

mount = /=/home/user/public_html/my-app.psgi
manage-script-name = true
Mon Aug 24 13:35:38 2015 - *** Operational MODE: single process ***
Mon Aug 24 13:35:38 2015 - mounting /home/user/public_html/my-app.psgi on /
2015/08/24 13:35:39 Application is started
Mon Aug 24 13:35:39 2015 - PSGI app 0 (/home/user/public_html/my-app.psgi) loaded in 1 seconds at 0x26cee08 (inter
Mon Aug 24 13:35:39 2015 - spawned uWSGI master process (pid: 6783)
Mon Aug 24 13:35:39 2015 - spawned uWSGI worker 1 (pid: 6807, cores: 1)

cause wrong:

SCRIPT_NAME=/
PATH_INFO=test.html

And ugly config make all FINE!

mount = =/home/user/public_html/my-app.psgi
manage-script-name = true

Notice UGLY loged message also
Mon Aug 24 13:37:21 2015 - mounting /home/user/public_html/my-app.psgi on

Mon Aug 24 13:37:21 2015 - *** Operational MODE: single process ***
Mon Aug 24 13:37:21 2015 - mounting /home/user/public_html/my-app.psgi on  <<< NOTING IS HERE
2015/08/24 13:37:21 Application is started
Mon Aug 24 13:37:21 2015 - PSGI app 0 (/home/user/public_html/my-app.psgi) loaded in 0 seconds at
Mon Aug 24 13:37:21 2015 - spawned uWSGI master process (pid: 6964)
Mon Aug 24 13:37:21 2015 - spawned uWSGI worker 1 (pid: 6988, cores: 1)

Now, vars looks good (y)

SCRIPT_NAME=
PATH_INFO=/test.html

So,
psgi = /home/feelsafe/public_html/feel-safe.net.psgi
is equivalent in mount manner:
mount = =/home/feelsafe/public_html/feel-safe.net.psgi

Thank you

PS. Can you route interface to a common denominator?
remove "psgi/wsgi-file/rack" and left only one "mount"
But it looks like all these are shortcuts to route or (seems similar too) route-run = uwsgi:</path/to/script.psgi>??

@unbit
Copy link
Owner

unbit commented Aug 25, 2015

So if i followed all well, the "/" mountpoint is not honoured as empty SCRIPT_NAME, right ?

@KES777
Copy link

KES777 commented Aug 25, 2015

right

@unbit
Copy link
Owner

unbit commented Aug 25, 2015

Ok, i was able to reproduce it, i'll push a fix in the next few minutes. Thanks again

@unbit unbit reopened this Aug 25, 2015
@unbit unbit closed this as completed in 772deaa Aug 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants