adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
530 stars 127 forks source link

scgi issue #257

Closed o3o closed 4 years ago

o3o commented 4 years ago

My code:

import arsd.cgi;

void hello(Cgi cgi) {
    cgi.setResponseContentType("text/plain");
    if("name" in cgi.get)
        cgi.write("Hello, " ~ cgi.get["name"]);
    else
        cgi.write("Hello, world!");
}

mixin GenericMain!hello;

My dub.sdl

name "arsd_cgi"
description "cgi test"

dependency "arsd-official:cgi" version="~>8.2.0"

subConfiguration "arsd-official:cgi" "scgi"

I use nginx, my nginx.conf

http {
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    sendfile        on;
    keepalive_timeout  65;

    server {
        access_log  ./logs/host.access.log  main;
        location / {
                include   scgi_params;
                scgi_pass localhost:8080;
        }
    }
}

So, I start app

./arsd_cgi --port 8080

when I open localhost:8080 in my browser:

./arsd_cgi --port 8080
o3o@snowball arsd_cgi]$ ./arsd_cgi --port 8080
std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2378): Unexpected 'G' when converting from type string to type ulong
----------------
/usr/include/dlang/dmd/std/conv.d:85 pure @safe ulong std.conv.parse!(ulong, immutable(char)[]).parse(ref immutable(char)[]) [0x557408cbd73d]
/usr/include/dlang/dmd/std/conv.d:1937 pure @safe ulong std.conv.toImpl!(ulong, immutable(char)[]).toImpl(immutable(char)[]) [0x557408cbd858]
/usr/include/dlang/dmd/std/conv.d:223 pure @safe ulong std.conv.to!(ulong).to!(immutable(char)[]).to(immutable(char)[]) [0x557408cbd5b7]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:3762 void arsd.cgi.doThreadScgiConnection!(arsd.cgi.Cgi, app.hello(arsd.cgi.Cgi), 5000000L).doThreadScgiConnection(std.socket.Socket) [0x557408cbc124]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:4368 void arsd.cgi.ConnectionThread.run() [0x557408cca204]
??:? void core.thread.context.Callable.opCall() [0x557408cfeb0c]
??:? thread_entryPoint [0x557408d27295]
??:? [0x7faee3341421]
??:? clone [0x7faee30efbf2]
std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2378): Unexpected 'G' when converting from type string to type ulong
----------------
/usr/include/dlang/dmd/std/conv.d:85 pure @safe ulong std.conv.parse!(ulong, immutable(char)[]).parse(ref immutable(char)[]) [0x557408cbd73d]
/usr/include/dlang/dmd/std/conv.d:1937 pure @safe ulong std.conv.toImpl!(ulong, immutable(char)[]).toImpl(immutable(char)[]) [0x557408cbd858]
/usr/include/dlang/dmd/std/conv.d:223 pure @safe ulong std.conv.to!(ulong).to!(immutable(char)[]).to(immutable(char)[]) [0x557408cbd5b7]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:3762 void arsd.cgi.doThreadScgiConnection!(arsd.cgi.Cgi, app.hello(arsd.cgi.Cgi), 5000000L).doThreadScgiConnection(std.socket.Socket) [0x557408cbc124]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:4368 void arsd.cgi.ConnectionThread.run() [0x557408cca204]
??:? void core.thread.context.Callable.opCall() [0x557408cfeb0c]
??:? thread_entryPoint [0x557408d27295]
??:? [0x7faee3341421]
??:? clone [0x7faee30efbf2]
std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2378): Unexpected 'G' when converting from type string to type ulong
----------------
/usr/include/dlang/dmd/std/conv.d:85 pure @safe ulong std.conv.parse!(ulong, immutable(char)[]).parse(ref immutable(char)[]) [0x557408cbd73d]
/usr/include/dlang/dmd/std/conv.d:1937 pure @safe ulong std.conv.toImpl!(ulong, immutable(char)[]).toImpl(immutable(char)[]) [0x557408cbd858]
/usr/include/dlang/dmd/std/conv.d:223 pure @safe ulong std.conv.to!(ulong).to!(immutable(char)[]).to(immutable(char)[]) [0x557408cbd5b7]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:3762 void arsd.cgi.doThreadScgiConnection!(arsd.cgi.Cgi, app.hello(arsd.cgi.Cgi), 5000000L).doThreadScgiConnection(std.socket.Socket) [0x557408cbc124]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:4368 void arsd.cgi.ConnectionThread.run() [0x557408cca204]
??:? void core.thread.context.Callable.opCall() [0x557408cfeb0c]
??:? thread_entryPoint [0x557408d27295]
??:? [0x7faee3341421]
??:? clone [0x7faee30efbf2]
std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2378): Unexpected 'G' when converting from type string to type ulong
----------------
/usr/include/dlang/dmd/std/conv.d:85 pure @safe ulong std.conv.parse!(ulong, immutable(char)[]).parse(ref immutable(char)[]) [0x557408cbd73d]
/usr/include/dlang/dmd/std/conv.d:1937 pure @safe ulong std.conv.toImpl!(ulong, immutable(char)[]).toImpl(immutable(char)[]) [0x557408cbd858]
/usr/include/dlang/dmd/std/conv.d:223 pure @safe ulong std.conv.to!(ulong).to!(immutable(char)[]).to(immutable(char)[]) [0x557408cbd5b7]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:3762 void arsd.cgi.doThreadScgiConnection!(arsd.cgi.Cgi, app.hello(arsd.cgi.Cgi), 5000000L).doThreadScgiConnection(std.socket.Socket) [0x557408cbc124]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:4368 void arsd.cgi.ConnectionThread.run() [0x557408cca204]
??:? void core.thread.context.Callable.opCall() [0x557408cfeb0c]
??:? thread_entryPoint [0x557408d27295]
??:? [0x7faee3341421]
??:? clone [0x7faee30efbf2]
std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2378): Unexpected 'G' when converting from type string to type ulong
----------------
/usr/include/dlang/dmd/std/conv.d:85 pure @safe ulong std.conv.parse!(ulong, immutable(char)[]).parse(ref immutable(char)[]) [0x557408cbd73d]
/usr/include/dlang/dmd/std/conv.d:1937 pure @safe ulong std.conv.toImpl!(ulong, immutable(char)[]).toImpl(immutable(char)[]) [0x557408cbd858]
/usr/include/dlang/dmd/std/conv.d:223 pure @safe ulong std.conv.to!(ulong).to!(immutable(char)[]).to(immutable(char)[]) [0x557408cbd5b7]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:3762 void arsd.cgi.doThreadScgiConnection!(arsd.cgi.Cgi, app.hello(arsd.cgi.Cgi), 5000000L).doThreadScgiConnection(std.socket.Socket) [0x557408cbc124]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:4368 void arsd.cgi.ConnectionThread.run() [0x557408cca204]
??:? void core.thread.context.Callable.opCall() [0x557408cfeb0c]
??:? thread_entryPoint [0x557408d27295]
??:? [0x7faee3341421]
??:? clone [0x7faee30efbf2]
std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2378): Unexpected 'G' when converting from type string to type ulong
----------------
/usr/include/dlang/dmd/std/conv.d:85 pure @safe ulong std.conv.parse!(ulong, immutable(char)[]).parse(ref immutable(char)[]) [0x557408cbd73d]
/usr/include/dlang/dmd/std/conv.d:1937 pure @safe ulong std.conv.toImpl!(ulong, immutable(char)[]).toImpl(immutable(char)[]) [0x557408cbd858]
/usr/include/dlang/dmd/std/conv.d:223 pure @safe ulong std.conv.to!(ulong).to!(immutable(char)[]).to(immutable(char)[]) [0x557408cbd5b7]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:3762 void arsd.cgi.doThreadScgiConnection!(arsd.cgi.Cgi, app.hello(arsd.cgi.Cgi), 5000000L).doThreadScgiConnection(std.socket.Socket) [0x557408cbc124]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:4368 void arsd.cgi.ConnectionThread.run() [0x557408cca204]
??:? void core.thread.context.Callable.opCall() [0x557408cfeb0c]
??:? thread_entryPoint [0x557408d27295]
??:? [0x7faee3341421]
??:? clone [0x7faee30efbf2]
std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2378): Unexpected 'G' when converting from type string to type ulong
----------------
/usr/include/dlang/dmd/std/conv.d:85 pure @safe ulong std.conv.parse!(ulong, immutable(char)[]).parse(ref immutable(char)[]) [0x557408cbd73d]
/usr/include/dlang/dmd/std/conv.d:1937 pure @safe ulong std.conv.toImpl!(ulong, immutable(char)[]).toImpl(immutable(char)[]) [0x557408cbd858]
/usr/include/dlang/dmd/std/conv.d:223 pure @safe ulong std.conv.to!(ulong).to!(immutable(char)[]).to(immutable(char)[]) [0x557408cbd5b7]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:3762 void arsd.cgi.doThreadScgiConnection!(arsd.cgi.Cgi, app.hello(arsd.cgi.Cgi), 5000000L).doThreadScgiConnection(std.socket.Socket) [0x557408cbc124]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:4368 void arsd.cgi.ConnectionThread.run() [0x557408cca204]
??:? void core.thread.context.Callable.opCall() [0x557408cfeb0c]
??:? thread_entryPoint [0x557408d27295]
??:? [0x7faee3341421]
??:? clone [0x7faee30efbf2]
std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2378): Unexpected 'G' when converting from type string to type ulong
----------------
/usr/include/dlang/dmd/std/conv.d:85 pure @safe ulong std.conv.parse!(ulong, immutable(char)[]).parse(ref immutable(char)[]) [0x557408cbd73d]
/usr/include/dlang/dmd/std/conv.d:1937 pure @safe ulong std.conv.toImpl!(ulong, immutable(char)[]).toImpl(immutable(char)[]) [0x557408cbd858]
/usr/include/dlang/dmd/std/conv.d:223 pure @safe ulong std.conv.to!(ulong).to!(immutable(char)[]).to(immutable(char)[]) [0x557408cbd5b7]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:3762 void arsd.cgi.doThreadScgiConnection!(arsd.cgi.Cgi, app.hello(arsd.cgi.Cgi), 5000000L).doThreadScgiConnection(std.socket.Socket) [0x557408cbc124]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:4368 void arsd.cgi.ConnectionThread.run() [0x557408cca204]
??:? void core.thread.context.Callable.opCall() [0x557408cfeb0c]
??:? thread_entryPoint [0x557408d27295]
??:? [0x7faee3341421]
??:? clone [0x7faee30efbf2]
std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2378): Unexpected 'G' when converting from type string to type ulong
----------------
/usr/include/dlang/dmd/std/conv.d:85 pure @safe ulong std.conv.parse!(ulong, immutable(char)[]).parse(ref immutable(char)[]) [0x557408cbd73d]
/usr/include/dlang/dmd/std/conv.d:1937 pure @safe ulong std.conv.toImpl!(ulong, immutable(char)[]).toImpl(immutable(char)[]) [0x557408cbd858]
/usr/include/dlang/dmd/std/conv.d:223 pure @safe ulong std.conv.to!(ulong).to!(immutable(char)[]).to(immutable(char)[]) [0x557408cbd5b7]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:3762 void arsd.cgi.doThreadScgiConnection!(arsd.cgi.Cgi, app.hello(arsd.cgi.Cgi), 5000000L).doThreadScgiConnection(std.socket.Socket) [0x557408cbc124]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:4368 void arsd.cgi.ConnectionThread.run() [0x557408cca204]
??:? void core.thread.context.Callable.opCall() [0x557408cfeb0c]
??:? thread_entryPoint [0x557408d27295]
??:? [0x7faee3341421]
??:? clone [0x7faee30efbf2]
std.conv.ConvException@/usr/include/dlang/dmd/std/conv.d(2378): Unexpected 'G' when converting from type string to type ulong
----------------
/usr/include/dlang/dmd/std/conv.d:85 pure @safe ulong std.conv.parse!(ulong, immutable(char)[]).parse(ref immutable(char)[]) [0x557408cbd73d]
/usr/include/dlang/dmd/std/conv.d:1937 pure @safe ulong std.conv.toImpl!(ulong, immutable(char)[]).toImpl(immutable(char)[]) [0x557408cbd858]
/usr/include/dlang/dmd/std/conv.d:223 pure @safe ulong std.conv.to!(ulong).to!(immutable(char)[]).to(immutable(char)[]) [0x557408cbd5b7]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:3762 void arsd.cgi.doThreadScgiConnection!(arsd.cgi.Cgi, app.hello(arsd.cgi.Cgi), 5000000L).doThreadScgiConnection(std.socket.Socket) [0x557408cbc124]
../../../.dub/packages/arsd-official-8.2.0/arsd-official/cgi.d:4368 void arsd.cgi.ConnectionThread.run() [0x557408cca204]
??:? void core.thread.context.Callable.opCall() [0x557408cfeb0c]
??:? thread_entryPoint [0x557408d27295]
??:? [0x7faee3341421]
??:? clone [0x7faee30efbf2]

Thank you very much

adamdruppe commented 4 years ago

On Mon, Aug 03, 2020 at 03:19:36PM -0700, o3o wrote:

    location / {
            include   scgi_params;
            scgi_pass localhost:8080;
    }

So, I start app

./arsd_cgi --port 8080

when I open localhost:8080 in my browser:

So you should be going to your nginx thing in the browser (maybe http://localhost/ or whatever, depends what port that's running on).

What you're doing here is trying to go directly to the scgi server in the browser itself, but the browser speaks http, not scgi. So every connection gets various protocol errors there.

With a config like this, you talk to nginx in the browser, then nginx talks to your cgi application on the backend through scgi.

o3o commented 4 years ago

Thank you for your reply.

Do you have an idea how to set up nginx?

adamdruppe commented 4 years ago

You basically did it right, you just need to actually go to the nginx port in your browser instead of the backend port.

On my system the config looks like this:

server {
        listen 80;

        location / {
                include   scgi_params;
                scgi_pass localhost:9001;
        }
}

So I go to port 80 in the browser (which is the http default) to use the website. If you put a listen 7000; in there, for example, you'd want to go to to http://localhost:7000/ in the browser.

o3o commented 4 years ago

It works like a charm! Thank you for your support and and for your great contribution to community.