2013年6月17日 星期一

django, nginx, uwsgi on macos

Basically I follow this tutorial to setup my dev environment. However, this tutorial is prepared for ubuntu but not for osx and I did suffer a lot from this difference. I would like to share what issues I encountered and what I did to workaround those issues.

I'm pretty new to these softwares and if any information provided below would cause any misunderstanding, please feel free to let me know.

My dev environment composed of those softwares:

  • nginx 1.4.1, installed via macports
  • python 3.3, install via macports
  • django 1.5.1, install via pip
  • uWSGI 1.9.12, installed via pip
The first problem is the command to start/restart nginx service.
  • to start: launchctl load -w /Library/LaunchDaemons/org.macports.nginx.plist
  • to stop: launchctl unload -w /Library/LaunchDaemons/org.macports.nginx.plist
The second problem is when using unix socket between nginx and uWSGI. I always get the error "permission denied". It won't be fixed if you just create this socket with permission#664 or #666. You have to change the owner of this file, too. Please refer to this for details. Or you can just change the permission for that file to #777. Please notice that it won't work if you just chmod and start uwsgi. Because every time you run uwsgi with unix-socket, it will overwrite the permission of that unix-socket. Therefore, please assign it permission with --chmod-socket option.

The third problem is I can't find mysite.wsgi (wsgi-script generated by django) in my project, instead, wsgi.py would exist. Passing this option "--wsgi-file wsgi.py" won't work. The right way to launch you django project is the call uwsgi in the parent folder of you project, like this:
uwsgi --socket mysite.sock --chmod-socket=777 --wsgi-file mysite\wsgi.py
It's trivial but would still take some time to fix it.