Nginx on OS X (For Pelican)

Installing nginx on OS X is fairly straight forward.

It involves using a pkg manager like homebrew . Additionally, if you want to use it with something like pelican , there are a couple tweaks I do to faciliate local development on my laptop.

nginx installation

Starting off, we install nginx with brew:

1brew install nginx

nginx startup

As the last part of the install, we need to link the plist and then load the plist so launchd will keep nginx running. We can do that with:

1ln -sfv /usr/local/opt/nginx/*.plist ~/Library/LaunchAgents

I make a tweak to the plist to keep nginx running (meaning that if I edit the config file and kill nginx, launchd will restart it for me). I put this bit right above the line <key>Label</key>.

1<key>KeepAlive</key>
2	<dict>
3	<key>SuccessfulExit</key>
4	<false/>
5</dict>

Loading the plist:

1launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist

nginx configuration

Now we can go edit the nginx config file (by defafult, brew puts this in /usr/local/etc/nginx).

Here is a snippet from the nginx config. I specify a root that is where I’m doing my pelican work, in the output directory. Of note, I enable autoindex for the ‘drafts’ directory because there is no index page. The idea being that for publication, you don’t want people rooting around in your drafts, and with out a direct link, it will (in essence) keep people out. For my deveopment machine, there is no harm in making it a little easier for me to look at drafts while I’m working on pages.

 1server {
 2	listen       8000;
 3	server_name  test.your_domain.com;
 4	root /Users/louisk/path/to/pelican/your_domain.com/output;
 5	index  index.html
 6	index.htm;
 7	location /drafts {
 8		autoindex on;
 9		allow 127.0.0.1;
10	}
11	error_page 500 502 503 504 /50x.html;
12	location = /50x.html {
13		root html;
14	}
15}

/etc/hosts

If you’re running nginx on a desktop or laptop, changes are you aren’t planning on doing a lot of web hosting with it. Additionally, you probably don’t want to run a DNS server (even a light weight one) either. Fortunately, you don’t have. Some modifications to /etc/hosts and we should be up and running. The reason I used test as a subdomain, is that I didn’t want to collide with any of the actual domain running external to the laptop (in case I want to have a browser page open with both the test site and the regular production site at the same time).

1127.0.0.1 test.your_domain.com

Now, you should be able to point your browser at ’test.your_domain.com:8000’ and you should see the proper content that pelican has generated.

Copyright

Comments