# Nginx on Mac help

**URL:** <https://www.ruby-forum.com/t/nginx-on-mac-help/106770>\
**Category:** Deployment\
**Created:** [June 13, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/nginx-on-mac-help/106770 "2007-06-13T22:55:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [June 13, 2007, 10:55pm UTC](https://www.ruby-forum.com/t/nginx-on-mac-help/106770/1 "2007-06-13T22:55:35Z")

</div>

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](http://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](http://mongrel);  
break;  
}  
}  
error\_page 500 502 503 504 /50x.html;  
location = /50x.html {  
root html;  
}  
}  
}  
########################################

Thank You,

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [June 14, 2007, 7:13am UTC](https://www.ruby-forum.com/t/nginx-on-mac-help/106770/2 "2007-06-14T07:13:28Z")

</div>

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](http://blog.nanorails.com)

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [June 14, 2007, 5:51pm UTC](https://www.ruby-forum.com/t/nginx-on-mac-help/106770/3 "2007-06-14T17:51:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [June 14, 2007, 9:28pm UTC](https://www.ruby-forum.com/t/nginx-on-mac-help/106770/4 "2007-06-14T21:28:42Z")

</div>

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-](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

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [June 14, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/nginx-on-mac-help/106770/5 "2007-06-14T22:37:56Z")

</div>

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/](http://lingon.sourceforge.net/)  
[2] [http://wiki.codemongers.com/NginxHttpMainModule#daemon](http://wiki.codemongers.com/NginxHttpMainModule#daemon)

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [June 14, 2007, 6:18pm UTC](https://www.ruby-forum.com/t/nginx-on-mac-help/106770/6 "2007-06-14T18:18:38Z")

</div>

On 6/15/07, Andy K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
