Adding django-socketio to existing Apache/mod_wsgi/Django site - django

Can anyone provide or link to a tutorial for adding django-socketio functionality to an existing Django site that uses Apache and mod_wsgi?
Can they work in parallel or does the runserver_socketio command need to handle all requests?
This Question is related but offers little practical information.
Thanks

You should be able to run the regular site behind a public facing server like Apache, with the runserver_socketio part just serving websockets on a separate port. As described in the question you linked to, you'll need to work out if it's possible to proxy websockets through your web server if that's a requirement for you, but as also mentioned the gevent server used by runserver_socketio is more than capable.
When running separate instances like this, the "out of band" functions won't work, as they depend on shared state:
django_socketio.broadcast(message)
django_socketio.broadcast_channel(message, channel)
django_socketio.send(session_id, message)
You'll also need to add the SOCKETIO_PORT to the regular Django project's settings so that it knows which port to use.

Related

Deploying Django on IIS and ngrok

I am trying to deploy Django on local host and "tunnel" using ngrok. The ngrok works but the IIS (Internet Information Manager) gives 500 Error <handler> scriptProcessor could not be found in <fastCGI> application configuration. Reference into fastcgi shows that this feature is deprecated but what is the replacement for serving Django using local server and ngrok. I also pip installed pyngrok. Can you suggest a clear solution?
FastCGI was deprecated in Django 6+ years ago, their docs say WSGI is the preferred alternative, and they provide a tutorial for types of WSGI deployments to get you started.
But you wouldn't use ngrok in this case, you'd serve it up with something like nginx or apache using a wsgi mod (also shown in their tutorial). Where you'd use ngrok is in development with Django's built-in dev server, and that's the full example provided in pyngrok's documentation.
Usually I'd provide actual sample code here, but what you're asking about are full end-to-end solutions, which is why I'm providing links. Without the full context and examples of what you've built, it's hard to tell you where it's going wrong—hard to provide specific solutions without specific examples of the problem. But these tutorials tutorials are for exactly what you're doing, so hopefully they can help you debug your own solution.

Deploy Go/Golang REST Web API on production

I am writing a backend web api for a mobile app. It should support HTTPS. Most of my experience in .NET, but for this one I want to use Go/Golang. I have a sample service ready, now I need to make sure that it is production ready.
In .NET I will just use IIS, but I have no clue what would be a good approach for Go.
Should I have nginx as reverse proxy, or I better use FastCGI ? And how to make sure that my go app is up and will run on system reboot ? should I use upstart or something similar ?
I've been using Nginx FastCGI with a Go webservice - they work well together. It's no harder to set up than HTTP reverse proxying - except for having to learn how to do it. The performance ought in principle to be a lot better, but I have no measurements to justify that hunch. My web service can work in both HTTP mode and FastCGI mode (one or other at a time), so I suppose I ought to do some benchmarking (note to self!).
If you want proper system startup (and you should), you need to learn how init scripts work. I sometimes cheat and start with an existing working script someone else wrote for a similar application and customise it to work with mine.
I've used nginx as a reverse proxy for my Go projects. I've found that it's a lot easier to set up useful server settings such as TLS, compression, etc., in nginx rather than as a pure Go server.
Keeping it alive on server reboot is a more complicated question. I would suggest learning how to write a script/whatever for your server's init daemon and just doing it that way.

Launching a Mezzanine site live

I'm new to mezzanine and Django. I have set up a site, everything is working but I can only launch the server on "development". I would like to access de site on the port 80 on the internet instead of internally, as I have no way other than redirecting the port via SSH to access it. I would like to know how to do that.
And another question, is Nginx included with Mezzanine automatically ? Cause I have a tuned up Nginx server there and I'm not sure what I need to do, if run it with my existing Nginx server or with the one included with Django if that is how it works .... thank you for bring some light on this.
NGINX is not included with Mezzanine, it's an entirely separate piece of software, similar to Apache.
Mezzanine includes a fabric script which can automatically set up a production server if you'd like to use it, and will install NGINX on the server for you, among many other things.
Given your question, I can't recommend enough that you read and understand all the related documentation on this topic. Start with the Mezzanine link below, it references many other documentation sites - Django, Fabric, NGINX, plus more.
Enjoy the adventure: http://mezzanine.jupo.org/docs/deployment.html

Use Django+Redis+Socket.io to build chat room, where to start?

I've heard of these three giant technologies would allow developers to build pub/sub paradigm which result in rapid server push experience.
I've got background on Django, but non of the other two. So just wondering, where can I kick off?
I currently use Gunicorn as django server, uses Nginx as a proxy to serve static files, uses Haproxy as a front-end load balancer. After I adopt new technology stack, can I keep them still?
You will probably encounter issues using Socket.io (which will try to use websocket) with Nginx. Nginx 1.0 does not support proxying of HTTP/1.1. You can use tcp_proxy to work around it. You might be able to find some forks for Nginx 1.1 that have websocket support though.
Check out this and this.
Start here:
http://gevent-socketio.readthedocs.org
and here:
https://github.com/abourget/gevent-socketio
There are some Django examples as to how to get started. Your tech. stack should allow you to run this without much problems.

Apache or Nginx to serve Django applications? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I want to deploy a Django web application, and hence I need to choose a web server to serve the Python files.
I should mention that my production site will be on a single server, which will host the database and the web server. As momentum picks, I aim to move the database to dedicated server etc.
Here are my questions:
Should I use one web server or two? The context of this question is that lots of people recommend using NginX to serve static media files and Apache to serve the Python, which beckons the following questions:
Why can't we use just one server. I understand Apache may be a beast at times, therefore I would suspect people to use NginX to serve BOTH static media files and python files.
If using one server, what is better, Apache or NginX. I am experienced in Apache, but I have heard only good things about NginX.
What are the advantages to using FastCGI as opposed to mod_wsgi?
Many thanks in advance
Should I use one web server or two? The context of this question is
that lots of people recommend using NginX to serve static media files
and Apache to serve the Python, which beckons the following questions:
Why can't we use just one server. I understand Apache may be a beast
at times, therefore I would suspect people to use NginX to serve BOTH
static media files and python files.
If you currently have no other sites that are already configured in one way or another, or you need some specific features that are mutually exclusive between the various servers, I see no reason for using multiple servers. This just adds unnecessary complexity and configuration.
If using one server, what is better, Apache or NginX.
I am experienced in Apache, but I have heard only good things about NginX.
As with all "which is better" questions this is usually a matter of preference. And to get a specific answer you probably need to ask more specific questions.
If you already have experience with a specific server and you just want to get up an running quickly, then I would suggest going with what you already know for the time being. You can always switch to another web server later.
On the other hand it's a good opportunity to learn about the alternatives.
tl;dr : I would go for what is easier to configure and manage. Personally I would go for a nginx and gunicorn, mainly because it's easy and there are plenty of resources available if you should get stuck.
I wouldn't worry too much about the performance until you actually need to. All staple web servers are tried and tested so it mostly comes down to the requirements of the application and the actual load, which needs monitoring and modeling and testing for fine tuning anyways.
What are the advantages to using FastCGI as opposed to mod_wsgi?
Differences and uses between WSGI, CGI, FastCGI, and mod_python in regards to Python?
articles to read (some old, some new);
http://gunicorn-docs.readthedocs.org/en/latest/deploy.html
https://docs.djangoproject.com/en/dev/howto/deployment/
http://serversforhackers.com/editions/2014/03/25/nginx/
http://blog.dscpl.com.au/2009/05/blocking-requests-and-nginx-version-of.html
http://www.thegeekstuff.com/2013/11/nginx-vs-apache/
http://raspberrywebserver.com/raspberrypicluster/comparing-the-performance-of-nginx-and-apache-web-servers.html
http://www.bearfruit.org/2013/04/19/reddit-is-melting-our-server-heres-what-we-did-nginx-apache-django-and-mysql/
In production, Apache + mod_wsgi or Nginx + mod_wsgi?
http://www.peterbe.com/plog/fcgi-vs-gunicorn-vs-uwsgi
http://www.aosabook.org/en/nginx.html
http://c2.com/cgi/wiki?PrematureOptimization
I'm not sure who is recommending to you that you use both Nginx and Apache, but that's a horrible idea. Whichever you choose, either will simply act as the reverse proxy, serving only static resources and handing everything else off to a subprocess like uwsgi.
I prefer Nginx because it's light-weight and extremely fast out of the box. Apache can be just as good, but requires building from source and knowing exactly what configuration to use to match Nginx. However, Apache has more features and is a little easier to work with. It's really up to you and the needs of your application.
However, whichever you choose, you only need one -- not both.
I think the best choices is virtualenv, uwsgi and nginx.
I changed all my servers now and I'm really happy with performance.
Here is good tutorial on how to setup you webserver
http://senya.pl/2011/03/sexy-nginx-uwsgi-stack-for-django-with-virtualenv/
Question 1) You can use just one server, but for serving static media a solution like lighttpd or nginx will be much faster. I would stick with Apache if you really want to use only one server, it has all the flexibility you need and it is the most common webserver.
Question 2) Depends on your purpose. You can find info here: Deploying Django (fastcgi, apache mod_wsgi, uwsgi, gunicorn)
I tried to follow the suggested link by Nicowernli, but senya.pl was down at that moment.
This seems like a good alternative tutorial....
Gonna try it, just read the first 2 chapters, but seems very complete and really step by step:
http://www.abidibo.net/blog/2012/04/30/deploy-django-applications-nginx-uwsgi-virtualenv-south-git-and-fabric-part-1/
The less, the better.
The best way to deploy Django application over Nginx is use uwsgi. It's pure WSGI and built in supported by new version Nginx.
I have used gunicorn + eventlet as the Python server, and nginx as the reverse proxy with great success. Recently I switched to uWSGI and it seems to be just as good of a solution if not better. I have yet to try apache and Django although I was an apache user prior to using Django. Here is a good write up on getting it all done: http://radtek.ca/blog/django-production-deployment-via-nginx-and-gunicorn-and-virtualenv/