[Mono-aspnet-list] CentOS + Mono + nginx

Ovidiu D ovidiudeac at gmail.com
Tue Apr 2 15:40:06 UTC 2013


Hi,

We have a setup here with mono + nginx + fastcgi + upstart on ubuntu 12.04
and it works fine.

I agree with Daniel's comment that you should probably use unix sockets if
the fastcgi server and the web server run on the same machine.

Also you probably want fastcgi-mono-server4 to use .NET 4.0

I can't help you with your error messages but what I can do is give you our
configuration files and you can start from there.

A short explanation:

We run 4 instances of the application and they are configured as an
upstream for nginx. The load balancing is done by ip_hash
There is a main service and 4 worker services. The worker services are
actual fastcgi instances. I'm not sure if you really need that but we did
that because we were plaing with nginx load balancing.

The "location ^~ ..." lines should make nginx handle the static files. This
way the fastcgi server only has to deal with the dynamic content.

When you create the directories make sure they have proper permissions. The
fastcgi socket has to be writable by the user www-data  as well  - or
whatever user is nginx process running under.

See below the configuration files. If you discover that we do something
wrong please let me know.

Hope this helps!
ovidiu

nginx configuration - goes to /etc/nginx/sites-enabled/myapp
**************************************************************

upstream myapp {
ip_hash;
server unix:/var/run/myapp/socket-1;
server unix:/var/run/myapp/socket-2;
server unix:/var/run/myapp/socket-3;
server unix:/var/run/myapp/socket-4;
}

server {
listen 80;
server_name myapp.com ;

access_log /var/log/myapp/nginx-access.log;
error_log /var/log/myapp/nginx-error.log;

root /opt/myapp;

location ^~ /bootstrap/ { }
location ^~ /css/ { }
location ^~ /img/ { }
location ^~ /js/ { }
location ^~ /jslib/ { }
location ^~ /Scripts/ { }

location / {
client_max_body_size 4096m;
fastcgi_pass myapp;
fastcgi_read_timeout 100;
include /etc/nginx/fastcgi_params;
}
}


This is the upstart script for our main service - goes to
/etc/init/myapp.conf
*******************************************************
description "MyApp service"
version "%%version%%"
author "...."

env RUN_DIR=/var/run/myapp
env USER=www-data
env GROUP=myapp

#disable the service for now
#start on runlevel [2345]
stop on shutdown

env WORKERS=4

pre-start script
logger "myapp: prestart..."

mkdir -p $RUN_DIR
chown $USER.$GROUP $RUN_DIR
chmod 770 $RUN_DIR

logger "myapp: starting $WORKERS workers"
for i in `seq 1 $WORKERS`
do
logger "myapp: Starting worker $i"
start myapp-worker N=$i
done
end script

script
#dummy process used to keep this instance alive
#When this instance is stopped all the worker processes will stop also
# because they have their stop on condition looks like this:
# stop on stopping myapp
while true; do sleep 1000; done
end script

This is the startup script for our worker service - goes to
/etc/init/myapp-worker.conf
*********************************************************
description "Myapp FastCGI worker"
version "%%version%%"
author "...."

instance $N
usage "N - the instance nubmer"

env APPS=/etc/myapp/webapps
env SOCKET=unix:/var/run/myapp/socket
env LOG=/var/log/myapp/fastcgi
env APP_DIR=/opt/myapp
env FASTCGI_SERVER=fastcgi-mono-server4
env MONO_ENV_OPTIONS="--gc=sgen" #This is recommended. The old style GC
does not compact the memory

umask 0002

expect fork

#this instance is started by 'start myapp' and is stopped by 'stop myapp'
stop on stopping myapp

respawn
respawn limit 10 5

setgid myapp
setuid www-data

exec $FASTCGI_SERVER --applications=/:$APP_DIR --socket=$SOCKET-$N
--logfile=$LOG-$N.log &




On Tue, Apr 2, 2013 at 4:42 PM, maxunique <rezkootvali at rambler.ru> wrote:

> from error.log
> [error] 4099#0: *1 upstream sent unexpected FastCGI record: 3 while reading
> response header from upstream, client: 192.168.1.2, server: [domain],
> request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host:
> "[domain]"
>
>
>
> --
> View this message in context:
> http://mono.1490590.n4.nabble.com/CentOS-Mono-nginx-tp4659199p4659204.html
> Sent from the Mono - ASP.NET mailing list archive at Nabble.com.
> _______________________________________________
> Mono-aspnet-list mailing list
> Mono-aspnet-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-aspnet-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-aspnet-list/attachments/20130402/a02f3fbc/attachment.html>


More information about the Mono-aspnet-list mailing list