Nginx on Mac help

Greetings,

I’m trying get an Nginx, mong-clust, mongrel, rails stack working on
an iMac mini that recently came into my possession.

I’ve never used Nginx, thus I’m sure I’m doing something wrong.

I installed nginx via port install… and it works and responds on :
80.

Now I’m trying to link the mongrel to nginx and the nginx tells me
my .conf syntax is ok but then says “test failed”, with no further
info.

My goal is to run a single rails app, I thought this the easiest
path. So the “localhost:80” should bring up my test rails app through
nginx.

Perhaps posting my current nginx.conf hack will help you help me…

########################################
user andy;
worker_processes 1;
error_log logs/error.log debug;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
#include conf/mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/plain;
upstream mongrel {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8001;
}
server {
listen 80;
#server_name example.com;
root /Users/andy/Sites/test_rails/public;
index index.html index.htm;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect false;
if (-f $request_filename/index.html) {
rewrite (.) $1/index.html break;
}
if (-f $request_filename.html) {
rewrite (.
) $1.html break;
}
if (!-f $request_filename) {
proxy_pass http://mongrel;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
########################################

Thank You,

Mac OS does not implement sendfile, so this could be your problem.

try:
sendfile off;

and see if it helps. If it does not, keep removing lines till you get
something that works, and start to build it back up (and let us know how
it
goes)

Cheers,
Pascal.

http://blog.nanorails.com

Well, when in doubt it helps to realize (and read) the error.log file.

I was getting Permission Denied when attempting to bind to :80. So I
su’d to root, but then it complained that the :80 address was already
in use.

Then I mercilessly killed the master and worker processes. Finally it
worked and my first Nginx stack is a go!

I’m feeling that killing processes is not a “best practice”, thus I’m
interested in any suggestions.

Now for a Debian…

Thank You,

/ak

On Jun 14, 2007, at 12:17 PM, Alain H. wrote:

I’m feeling that killing processes is not a “best practice”, thus I’m
interested in any suggestions.

If you want a more ordered manner for starting and stopping server
processes on the Mac you probably want to look into using launchd to
start up and stop nginx.

launchd or StartupItems

This is a bit of a mess.

StartupItems is the old way: you put a script and some metadata in
the /Library/StartupItems folder (see other ones in there for an
example, or grab http://www2.entropy.ch/download/pgsql-
startupitem-1.2.pkg.tar.gz). apps are started and stopped as defined
in the script, and can be turned on or off (for restart) in the /etc/
hostconfig file.

The good news is that this is fairly easy to set up. The bad news is
it’s somewhat deprecated and will go away at some point in the future.

launchd is the new way: you put an xml config file in one of a
number of places and the system magically does the right thing,
starting, stopping, restarting, and monitoring your process as
necessary. It’s magic in both good and bad ways.

The good news is that this is the future that Apple intends to
support, and that it’s (allegedly) pretty powerful once you
understand how it all works. The bad news is it’s harder to
understand, harder to set up, and doesn’t entirely work yet for some
purposes. Specifically it doesn’t deal well with processes that
detach at start and then do a clean shutdown by sending a signal from
another process (e.g. apachctl, pg_ctl).

Short of learning all about both, you can probably summarize the
decision as: If you can run nginx in a shell and then hit ctrl-c, or
if sending it a HUP causes a clean shutdown, then launchd is probably
the “right” way. If you want to get this working today and are
willing to spend more time on The Right Thing later then StartupItems
is probably your best bet.

-faisal

On 14 Jun 2007, at 20:27, Faisal N Jawdat wrote:

detach at start and then do a clean shutdown by sending a signal from
another process (e.g. apachctl, pg_ctl).

I’ve found Lingon [1] to be very helpful in understanding and setting
up launchd jobs.

Short of learning all about both, you can probably summarize the
decision as: If you can run nginx in a shell and then hit ctrl-c, or
if sending it a HUP causes a clean shutdown, then launchd is probably
the “right” way.

It’s possible to stop the nginx master process going into the
background by adding:

daemon: off;

to your nginx.conf. [2]

BTW, Sending nginx a HUP causes it to reload it’s configuration not
shutdown.

Cheers,

Chris

[1] http://lingon.sourceforge.net/
[2] http://wiki.codemongers.com/NginxHttpMainModule#daemon

On 6/15/07, Andy K. [email protected] wrote:

Then I mercilessly killed the master and worker processes. Finally it
worked and my first Nginx stack is a go!

I wouldn’t worry too much about having to kill a process. nginx is
pretty good
about not leaving anything stray if you send it a kill message.

I’m feeling that killing processes is not a “best practice”, thus I’m
interested in any suggestions.

If you want a more ordered manner for starting and stopping server
processes on the Mac you probably want to look into using launchd to
start up and stop nginx. I’m afraid I don’t have any specific
information on how to get nginx and launchd to play nice with one
another but I hope Google will be a good guide.

Alain