Deploy a real-time web app with swampdragon x apache

(In general, if you look at how to write httpd.conf at the bottom, it should be a trigger ...)

Premise

Assuming you're using the python module django, there are probably several ways to implement the real-time Web, but there aren't many when it comes to taking advantage of those prerequisites (= can be used as an extension of the python module or Django). What comes out after a light examination

Around.

At that time, it was updated more than channels, and I chose swampdragon because it has more Japanese documents (examples of use) than swampdragon (although both are few).

Currently (16/12/29) it seems that the update of the official website has already stopped, but at that time (16/07 / xx) I chose that (although the official website was closed at that time) .. As a result, I will summarize the process of deploying with difficulty.

In addition, the module installation procedure is omitted, and the story is all about what was installed and how it was set.

What you want to deploy

The development environment of the application you want to deploy is

In addition, the following was introduced as a module.

The deployment destination is CentOS 7, which is set up on AWS and has no initial settings. Since it is clean, I had to enter it from apache for the time being.

Preparing the deployment destination

Create a foundation for running web applications on CentOS7. This time we will introduce the following.

If both are the latest, there is no problem (should). By the way, mod_wsgi is also introduced to prepare the wsgi environment.

In addition, since the version of Python that was included in CentOS 7 was 2.7, I installed Python 3.5.1 so that it can be used with commands of the form python3.5.

Also, if you install redis without thinking about it, only 2.8 and earlier versions will be included, so I referred to here and installed it directly.

That's the main subject of deployment.

Deploy (ordinary procedure for django)

The application I wanted to deploy was placed on github, so I cloned it to the following directory and placed it.

/var/www/cgi-bin/

The location is like the default setting of apache.

After that, without thinking about anything in particular, modify httpd.conf according to Official document of different version.

However, this alone does not work.

In order to realize the real-time Web, it was necessary to route swampdragon to the server and start the redis server.

Deploy (procedure when there is swampdragon)

This time, the following four servers need to run on CentOS.

Of these, the former two can be started from the following commands.

systemctl start httpd
systemctl start postgresql

It runs in the background, so you won't be overwhelmed by the console.

The problem is the latter two. django itself runs on apache, but swampdragon introduced as its module needs to set up a server separately from django. And when redis also starts the server, other operations will not be possible.

Therefore, tmux was newly introduced. By simply introducing tmux and splitting the console, simultaneous startup is possible.

But the problem still remains. That's the routing from apache to the swampdragon server. I had a lot of trouble because I couldn't find any literature about this.

The contents of the final apache settings (httpd.conf) are as follows (the app path is blurred).

Listen 80
Listen 443

<VirtualHost *:443>
ProxyPass /data ws://127.0.0.1:9999/data
ProxyPassReverse /data ws://127.0.0.1:9999/data
ProxyPass /settings.js http://127.0.0.1:9999/settings.js
ProxyPassReverse /settings.js http://127.0.0.1:9999/settings.js
ProxyPreserveHost On
ProxyRequests Off
ProxyVia On
</VirtualHost>

LoadModule wsgi_module /usr/lib64/httpd/modules/mod_wsgi.so
WSGIPythonPath /var/www/cgi-bin/path/to/app:/usr/local/bin/python3.5/site-packages
DocumentRoot "/var/www/cgi-bin/path/to/documentroot"
Alias /static/ /var/www/cgi-bin/path/to/static/

<Directory /var/www/cgi-bin/path/to/app/>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
WSGIScriptAlias / /var/www/cgi-bin/path/to/wsgi.py

In addition, ~: //127.0.0.1:9999/~ is the default setting (should be) when swampdragon was introduced.

Below the Load Module in the lower half, it's almost exactly what the django official website says.

The liver is the setting of 443 ports. swampdragon has two communications to receive. /Data for websocket communication and /settings.js for http.

If you set it as a virtual host and transfer it to a separate swampdragon server, it will be thrown further to the redis server and session information will be saved.

Summary

Eventually, you should be able to launch a real-time web application with a command like this.

tmux
systemctl start postgresql
systemctl start httpd
sudo redis-server /etc/redis.conf

python3.5 server.py

When using swampdragon

  1. Apache and redis required
  2. You need to specify the transfer of /data and /settings.js respectively
  3. Probably the fastest way to set up a server using tmux.

The above is the story of the first manual deployment.

Recommended Posts

Deploy a real-time web app with swampdragon x apache
Deploy a web app created with Streamlit to Heroku
How to deploy a web app made with Flask to Heroku
(Failure) Deploy a web app made with Flask on heroku
Play like a web app with ipywidgets
Daemonize a Python web app with Supervisor
Create a simple web app with flask
Deploy a Python 3.6 / Django / Postgres web app on Azure
Deploy a Django app made with PTVS on Azure
Real-time web with Django Channels
Set up a web server with CentOS7 + Anaconda + Django + Apache
Real-time object detection Android app with TensorFlow and Camera X
When I deploy a Django app with Apache2 and it no longer reads static files
Deploy a Django application with Docker
Creating a simple app with flask
Build a web application with Django
Deploy a Python app on Google App Engine and integrate it with GitHub
Web App Development Practice: Create a Shift Creation Page with Django! (Introduction)
Machine Learning x Web App Diagnosis: Recognize CAPTCHA with Cloud Vision API
Until you publish (deploy) a web application made with bottle on Heroku
Deploy flask app with mod_wsgi (using pipenv)
[Python] A quick web application with Bottle!
Easy web app with Python + Flask + Heroku
I can't deploy with google app engine
Run a Python web application with Docker
Let's make a web framework with Python! (1)
Create a web service with Docker + Flask
Make a desktop app with Python with Electron
Let's make a web framework with Python! (2)
I made a WEB application with Django
A web app that just does Hello World with Go's net / http package
Connect Scratch X and Digispark with a bottle
How to develop a cart app with Django
Vienna with Python + Flask web app on Jenkins
GUI automation with Python x Windows App Driver
Start a simple Python web server with Docker
Launch a web server with Python and Flask
How to create a multi-platform app with kivy
Extract data from a web page with Python
Web App Development Practice: Create a Shift Creation Page with Django! (Write a base template)
Web App Development Practice: Create a Shift Creation Page with Django! (Authentication system processing)
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a web server --3. Use MySQL
Web App Development Practice: Create a Shift Creation Page with Django! (Experiment on admin page)