Anybody familiar with Nginx?



  • Update TL;DR: This is 'SOLVED': http://what.thedailywtf.com/t/anybody-familiar-with-nginx/1881/16 & http://what.thedailywtf.com/t/anybody-familiar-with-nginx/1881/32

    (I have no previous experience with Nginx, only apache - after reading about Nginx I believe it will be very appropriate for this project though) I've been bashing my face against configuring nginx to work with mono, and I think I'm fairly close. The problem: Nginx displays my default index.html, but fails with the following:

    No Application Found

    Unable to find a matching application for request:

    Host 192.168.1.5
    Port 80
    Request Path /test.aspx
    Physical Path /wwwjail/test.aspx

    fastcgi_params - added the following two lines:

    fastcgi_param   PATH_INFO               "";
    fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
    

    using the following in my sites-available folder / default - I kind of suspect my server_name and my init.d file aren't lining up.

    server {
            listen 80;
            root /wwwjail;
            index Default.aspx index.aspx index.html;
            server_name *.twitchbot.us;
    
            location / {
                    try_files $uri $uri/ /Default.aspx /index.html =404;
            }
    
            location ~ \.(aspx|asmx|ashx|asax|ascx|soap|rem|axd|cs|config|dll)$ {
                    fastcgi_index /index.html;
                    fastcgi_pass 127.0.0.1:9000;
                    include /etc/nginx/fastcgi_params;
            }
    }
    

    In my init.d folder I created /mono-fastcgi and have the following file in there (I suspect this is where i'm fucking up, as i'm accessing the page over lan not localhost):
    twitchbot.us

    <apps>
    <web-application>
            <name>twitchbot.us</name>
            <vhost>*</vhost>
            <vport>80</vport>
            <vpath>/</vpath>
            <path>/wwwjail</path>
    </web-application>
    </apps>
    

    and I also executed the following command:

    fastcgi-mono-server4 --appconfigdir /etc/init.d/mono-fastcgi /socket=tcp:127.0.0.1:9000 /logfile=/var/log/mono/fastcgi.log &
    

    On my windows machine i've added the following host file entries

    192.168.1.5 twitchbot.us
    192.168.1.5 www.twitchbot.us
    


  • I think the problem is that you're putting configuration data into a file (in the wrong place) and then telling fastcgi-mono-server4 that the file is a directory.



  • I think the purpose is to tell fastcgi-mono-server4 where the server configuration files are, and the server name points at the actual configuration file... but... I'm struggling getting that concept to work. Have a proposal for change?



  • Not quite. But /etc/init.d is where daemon startup scripts go.

    Unless fastcgi-mono-server4 is ridiculous, the --appconfigdir flag should be a directory. And /etc/init.d/mono-fastcgi is a file.

    Where did you get your recipe from? I've got to wait for a project to compile, so I'll dig a little.



  • http://www.philliphaydon.com/2013/06/setting-up-mono-on-nginx/

    To also preface this: I am also not a linux user, so I'm doing brand new linux install, and nginx install, and a mono install on top of it (though I'm familiar with linux/mono compilation for very basic stand alone apps)

    http://www.mono-project.com/FastCGI_Nginx

    fastcgi-mono-server4 --appconfigdir /etc/init.d/mono-fastcgi /socket=tcp:127.0.0.1:9000 /logfile=/var/log/mono/fastcgi.log &
    

    Actually just realized: There is a different line in this link than the other one I was using, this one contains an application definition, and the other one didn't.

    fastcgi-mono-server2 /applications=www.domain1.xyz:/:/var/www/www.domain1.xyz/ /socket=tcp:127.0.0.1:9000
    


  • That /etc/init.d/mono-fastcgi thing isn't exactly best practices for Linux, but if it works, it will at least get you started.

    Presumably, you'd want to do something like:

    mkdir /etc/mono-fastcgi
    

    put the web app configuration file in there, and call

    fastcgi-mono-server4 --appconfigdir /etc/mono-fastcgi /socket=tcp:127.0.0.1:9000 /logfile=/var/log/mono/fastcgi.log &
    

    instead. But like I said, that can wait.

    Have you seen any error messages? Is nginx logging any errors when you try to visit the app? (/var/log/nginx/ has an error_log or errors.log, I forget which)



  • Well, I can't execute the fastcgi command directly any more because it's already bound (any idea how to unbind that command to test?

    /index.html works, test.aspx gives a 504 gateway timeout now

    error log

    2014/07/26 10:43:28 [error] 1798#0: *1 upstream timed out (110: Connection time$
    

    access log



  • Let's see. So you ran fastgi-mono-server for with an & at the end. So it forked the process. So you want to do:

    ps -C  fastcgi-mono-server4
    

    get the pid, and then run:

    kill <pid>
    

    While you're at it, check in /etc/init.d/ to see if fastcgi-mono has any start up scripts.

    If you find an entry in /etc/init.d, you can start it (the official, easy way) with sudo /etc/init.d/name start and stop it with sudo /etc/init.d/name stop

    And check /etc/default (maybe it's /etc/defaults) to see if there are any entries for fastcgi-mono.



  • ps -C fastcgi-mono-server4
    PID TTY TIME CMD

    No pids here.

    I think I found it in /var/run/nginx.pid - let me try now.

    That... doesn't appear to have resolved it, that just killed nginx, not the socket



  • That's nginx's pid. You can stop nginx with /etc/init.d/nginx stop (if you wanted)



  • Anyway, do:

    ps aux | less
    

    and look for fastcgi-mono-server4. You can use the arrow keys to scroll in less. Hit q when you're ready to exit less.

    And kill that pid.

    And then do /etc/init.d/nginx start to restart that.



  • root 1771 0.0 0.1 330484 22104 pts/2 Tl 10:38 0:00 /usr/bin/mono /usr/lib/mono/4.5/fastcgi-mono-server4.exe /applications=www.twitchbot.us:/:/wwwjail/twitchbot.us/ /socket=tcp:127.0.0.1:9000

    Ok, kill 9'd it because i want to nuke it from orbit.



  • Yeah, just a plain kill 1771 should do it (if fastcgi-mono-server4.exe is following standards...) kill defaults to sending a -9. You can do a -15 for really stubborn programs.

    So, if I understand the state of your machine, fastcgi-mono-server is not running. nginx is running and set up to connect to a fastcgi socket at localhost:9000 (if it's not running, go ahead and start it with /etc/init.d/nginx start)

    So now we need to figure out how to start fastcgi-mono-server4 so that it binds to socket 9000.



  • @Captain said:

    That /etc/init.d/mono-fastcgi thing isn't exactly best practices for Linux, but if it works, it will at least get you started.

    Presumably, you'd want to do something like:

    mkdir /etc/mono-fastcgi
    

    put the web app configuration file in there, and call

    fastcgi-mono-server4 --appconfigdir /etc/mono-fastcgi /socket=tcp:127.0.0.1:9000 /logfile=/var/log/mono/fastcgi.log &
    

    instead. But like I said, that can wait.

    Have you seen any error messages? Is nginx logging any errors when you try to visit the app? (/var/log/nginx/ has an error_log or errors.log, I forget which)

    I've made this change, and I'm back to this error:

    No Application Found
    
    Unable to find a matching application for request:
    
    Host	twitchbot.us
    Port	80
    Request Path	/test.aspx
    Physical Path	/wwwjail/test.aspx
    


  • Okay, go ahead and kill fastcgi-mono-server4.exe again.

    And actually, this time, run it without the & at the end of the invocation. That way, you can just hit ctrl-c in that terminal to kill it.

    Finally, try it this way:

    fastcgi-mono-server4 --appconfigdir /etc/mono-fastcgi --port 9000


  • fastcgi-mono-server4 --appconfigdir /etc/mono-fastcgi --port 9000
    [2014-07-26 11:18:06Z] Error Error: Pipe socket is not bound.

    I've found a winner!

    fastcgi-mono-server4 /applications=www.twitchbot.us:/:/wwwjail/ /socket=tcp:127.0.0.1:9000&
    

    Huzzah! Thanks for your help! I picked up several new commands I can use for troubleshooting now. I've added them to my cheat sheet.



  • Very nice!

    Check out the answer to: http://stackoverflow.com/questions/20477176/how-to-run-process-in-other-user-account-in-init-d

    to get it to run with the start-stop-daemon (so you can just do /etc/init.d/monoserve start and stop)



  • Doing a quick reboot of the server to see if it all reconnects automagically



  • It won't unless you have a script in /etc/init.d and it's registered to start up.



  • nginx does autostart, mono does not. What type of script does init.d need?



  • Yeah, make that monoserve script in that SO question.

    I'll find the command you need to "register" it:

    sudo update-rc.d monoserve defaults

    (assuming you call the script monoserve)



  • That stack overflow link has like... nothing in the accepted answer, and the comments are... scattered at best.



  • https://gist.github.com/alobato/1968852 has a startup script example. You'll want to change it, though.

    Of note is the NAME variable, the DAEMON variable, and the DAEMON_OPTS variable.



  • so something like this?

    NAME=twitchbot.us
    PIDFILE=/var/run/$NAME.pid
    #This is the command to be run, give the full pathname
    DAEMON=fastcgi-mono-server4 
    DAEMON_OPTS="/applications=www.twitchbot.us:/:/wwwjail/twitchbot.us,twitchbot.us:/:/wwwjail/twitchbot.us /socket=tcp:127.0.0.1:9000&"
     
    export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
    

    to replicate this?

    fastcgi-mono-server4 /applications=www.twitchbot.us:/:/wwwjail/twitchbot.us,twitchbot.us:/:/wwwjail/twitchbot.us /socket=tcp:127.0.0.1:9000&```


  • That's the idea.

    You'll want the full path to fastcgi-mono-server4. You can do which fastcgi-mono-server4 from the command line to find the full path.

    And also, get rid of the '&' in the DAEMON_OPTS line.

    And, you'll presumably name the script twitchbot.us in the /etc/init.d directory. So you'd want to run:

    sudo update-rc twitchbot.us enable
    

    It will then start up automatically at boot.



  • update-rc: command not found

    update-rc.d: warning: /etc/init.d/twitchbot.us missing LSB information
    update-rc.d: see http://wiki.debian.org/LSBInitScripts
    System start/stop links for /etc/init.d/twitchbot.us do not exist.



  • Oops, try sudo update-rc.d twitchbot.us defaults



  • update-rc.d twitchbot.us defaults
    update-rc.d: warning: /etc/init.d/twitchbot.us missing LSB information
    update-rc.d: see http://wiki.debian.org/LSBInitScripts
    Adding system startup for /etc/init.d/twitchbot.us ...
    /etc/rc0.d/K20twitchbot.us -> ../init.d/twitchbot.us
    /etc/rc1.d/K20twitchbot.us -> ../init.d/twitchbot.us
    /etc/rc6.d/K20twitchbot.us -> ../init.d/twitchbot.us
    /etc/rc2.d/S20twitchbot.us -> ../init.d/twitchbot.us
    /etc/rc3.d/S20twitchbot.us -> ../init.d/twitchbot.us
    /etc/rc4.d/S20twitchbot.us -> ../init.d/twitchbot.us
    /etc/rc5.d/S20twitchbot.us -> ../init.d/twitchbot.us

    That looks more like it did something.



  • Yup, this step worked. Now you just have to test the script. Run sudo chown root:root /etc/init.d/twitchbot.us && sudo chmod +x /etc/init.d/twitchbot.us && reboot now



  • So many magical incantations.

    Will run it, the reboot will take a few minutes though.



  • sudo chown root:root makes sure the script is owned by root (you want this so only root can modify it). chmod +x makes sure the script is executable.



  • I don't think that worked, fastcgi still appears to be disabled on reboot.

    Trying this one now:

    #!/bin/sh
    
    ### BEGIN INIT INFO
    # Provides:          monoserve.sh
    # Required-Start:    $local_fs $syslog $remote_fs
    # Required-Stop:     $local_fs $syslog $remote_fs
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: Start fastcgi mono server with hosts
    ### END INIT INFO
    
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    DAEMON=/usr/local/bin/mono
    NAME=monoserver
    DESC=monoserver
    
    MONOSERVER=$(which fastcgi-mono-server4)
    MONOSERVER_PID=$(ps auxf | grep fastcgi-mono-server4.exe | grep -v grep | awk '{print $2}')
    
    WEBAPPS="www.twitchbot.us:/:/wwwjail/twitchbot.us/,twitchbot.us:/:/wwwjail/twitchbot.us/"
    
    case "$1" in
            start)
                    if [ -z "${MONOSERVER_PID}" ]; then
                            echo "starting mono server"
                            ${MONOSERVER} /applications=${WEBAPPS} /socket=tcp:127.0.0.1:9000 &
                            echo "mono server started"
                    else
                            echo ${WEBAPPS}
                            echo "mono server is running"
                    fi
            ;;
            stop)
                    if [ -n "${MONOSERVER_PID}" ]; then
                            kill ${MONOSERVER_PID}
                            echo "mono server stopped"
                    else
                            echo "mono server is not running"
                    fi
            ;;
    esac
    
    exit 0
    

    This script worked! Huzzah!



  • @Captain said:

    kill defaults to sending a -9. You can do a -15 for really stubborn programs.

    Other way around. 15 is SIGTERM, as in "please terminate ASAP". 9 is SIGKILL as in "I KEEL U"



  • @Matches said:

    WEBAPPS="www.twitchbot.us:/:/wwwjail/twitchbot.us/,twitchbot.us:/:/wwwjail/twitchbot.us/"

    Do either/both of these work for you?
    http://twitchbot.ddns.net/index.html
    http://twitchbot.ddns.net/test.aspx

    For me, I think index.html is working local/remote, and test.aspx is only working locally.


  • Discourse touched me in a no-no place

    Neither work from here - just get the Chrome ERR_CONNECTION_TIMED_OUT message.



  • I disabled the firewall, would you mind trying again?

    Now both work for me.


  • Discourse touched me in a no-no place

    Yeah, that works.

    Thanks for stopping by, but there isn't anything here.
    and
    Hello World! Got an aspx page running on nginx!!!


  • Alright, nice - so the servers working and now the problem is just the firewall. I can deal with that.

    Thanks much.

    There we go, firewall re-enabled with port 80 open. Should be clean now.



  • Googling "nginx vport" returned TDWTF as the fifth result. Not sure how I feel about that.

    Trying to figure out how to get nginx to recognize a second domain to go along with twitchbot.us now, I've set it to bot.menu, we'll see how it goes. Just ran the update rc.d command, which hopefully is all that is left that needed to be done.

    Son of a bitch, i upgraded from 1.4.x to 1.6 and they literally removed two of the directories that contained my site information.

    Why do edits bump my topic to the top of the list?

    Checklist, based on tonight's work after the nginx upgrade debacle.

    • Update /etc/nginx/nginx.conf
    • Update /etc/nginx/sites-enabled
    • Ensure fastcgi-mono-4 is installed
    • Ensure init.d script is updated (see above)
    • Ensure rc.d update is complete (see above)
    • Ensure /etc/mono-fastcgi is configured (see above)


  • To get nginx to respond to two different domains, stick two different files in /etc/nginx/sites-enabled. Put a server configuration in each one:

    server {
      listen 80;
      listen [::]:80;
    
      root /var/www/test.com/html;
      index index.html index.htm;
    
      server_name test.com www.test.com;
    
      location / {
        try_files $uri $uri/ =404;
      }
    }
    

    You can bind lots of servers to a single port. If the different names are actually pointing at the same resource, you can just have lots of server_names, like in this example.

    Also, if you're not going to use deployment management, at least use git in /etc


  • Discourse touched me in a no-no place

    @Matches said:

    Googling "nginx vport" returned TDWTF as the fifth result. Not sure how I feel about that.

    #4, here, now.



  • Yeah I got it working last night. Binding ipv6 messes it up though with a double bind error that I'll have to look in to tonight. It's not too important yet due to only using v4, but might as well fix it early.


Log in to reply