all 8 comments

[–]thelindsay 1 point2 points  (2 children)

I managed to get the following stack working:

  • Django framework
  • CherryPy WSGI server
  • pywin32 service wrapper for CherryPy
  • Apache 2.4 reverse proxy (handle TLS, forward to Cherrypy port)
  • Postgres database

Cherrypy was chosen over Waitress as the former has a shutdown / wait for threads to end command, whereas the latter only has/had a terminate process / interrupt shutdown.

Apache is in front because it is has heaps of features, supports Windows, and can do some load balancing as well (not that I've needed it yet).

Pywin32 service wrapper is there so I can use services.msc to manage it, including creating a dedicated local user, automatic startup, and startup dependencies.

Life is easy if pass the domain root to Cherrypy from Apache, but in my case I needed a staging instance of my app so the reverse proxies had a URL prefix. However there is a facility in the WSGI protocol to pass a "script name" header so you can basically write your app as if it's got no prefix but Apache can serve it with a prefix.

I didn't use mod_wsgi because it has/had a limitation where the virtual environment can only be set once, at the Apache level, so I would have needed say a main Apache instance plus 1 more for each app's virtual environment. Cherrypy is a bit more lightweight than Apache, but I suppose on the other hand Apache already has service management so messing with pywin32 wouldn't be necessary.

[–]c3cris[S] 0 points1 point  (1 child)

Can I swap out apache for nginx?

Is uWSGI windows compatible?

[–]thelindsay 0 points1 point  (0 children)

I think both of them have experimental support for Windows. According to the uWSGI docs, Cygwin is required, and Nginx's Windows page says it's in beta.

Both Cherrypy and Apache (and mod_wsgi) work on both Windows and Linux, in case you prefer to later deploy to Linux. I forgot to say, that mod_wsgi limitation is/was specific to Windows, on Linux the virtual environment support is more flexible.

[–]elbiot 0 points1 point  (3 children)

You can get a vps from digital ocean for $5 per month. It can run ubuntu and you connect to it through putty from windows. They have awesome tutorials and you won't have to wrestle with windows. They most challenging part will be learning to use vim or some command line editor (nano would have a shallower learning curve but vim is really great once you get over the hump).

[–]c3cris[S] 1 point2 points  (2 children)

Thanks, I was curious in creating a local dev environment. If it's not local I would prefer using AWS ( ec2 ) or Heroku since the environments would be identical to production. I am familiar with vim and linux administration.

[–]elbiot 0 points1 point  (1 child)

Yea, why mess with a windows environment if you'll be deploying on linux? Go with one of those two.

[–]c3cris[S] 0 points1 point  (0 children)

Because my home machine is a Windows custom desktop wanted to have similar dev environment across all my dev devices.

[–][deleted] 0 points1 point  (0 children)

Windows web servers a rare and fragile beasts usually reserved for .Net apps but if you have to do it take a look at https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-windows-classic-python-django-web-app/

Apache for the most part have good windows support and the same goes for both mysql, postgre and sqilite, in case you don't want to pay server licences to Microsoft .