python - Multiple mod_wsgi apps on one virtual host directing to wrong app - Stack Overflow

 

mod_wsgi multiple applications

Also here's the carlosguadian.tk file for both applications. import os import sys path = '/var/www/py/site1' if path not in carlosguadian.tk: carlosguadian.tk(path) carlosguadian.tkault("DJANGO_SETTINGS_MODULE", "carlosguadian.tkgs") from carlosguadian.tk import get_wsgi_application application = get_wsgi_application() Now, here's my problem. Multiple mod_wsgi apps on one virtual host directing to wrong app. Effectively, for any given number of worker processes, it cycles through the total number of them sending the request to whichever one it hit first regardless of the WSGIScriptAlias directive. No matter what I do (setting WSGIProcessGroup, daemon mode vs. What is the alternative solution to support multiple wsgi applications then? If you have more than one WSGI application, then you simply need to create multiple mod_wsgi daemon process groups and delegate each WSGI application to run in its own daemon process group. With that done you can then happily set WSGIApplicationGroup to %{GLOBAL} for both.


Virtual Environments — mod_wsgi documentation


So you developed a cool AI algorithm and want to show it off through a web service? You know a lot about AI algorithms and Python, but not as much about web technologies? If you answered yes to any of these questions, the information in this post should be helpful. Hopefully, others working on a similar task will find this information helpful. I migrated my website to Amazon Lightsail few months ago and very happy so far. I particularly like the snapshot feature that enables painfree upgrade to a more powerful host.

One feature that is particularly important for hosting deep learning applications that is lacking on Lightsail — hosts with GPUs. Hopefully these will be available soon. For setting up my web service I needed to install Python 3. My default Bitnami installation came with Python 2. Since my Python code was based on Python 3. Instructions for installing core Python 3. The steps listed above will install the binary version of Python 3. The development version can be installed using the following command, mod_wsgi multiple applications.

Next, I installed Pytorch. Since the core Linux directories are not modified, mod_wsgi multiple applications, we can run this command without sudo, mod_wsgi multiple applications.

Next, a mod_wsgi multiple applications words about Linux permissions. Linux has an elaborate system for managing file ownership and permissions. There are two concepts — ownership and permissions. A file or directory has an owner and belongs to a group. Those are managed by the chmod command.

I will not go into this topic in further detail as there are many articles on the web this for example that do a good job at explaining how to manage ownership and permissions. Understanding these concepts is quite important as incorrect ownership and permissions settings can cause things to not work in mysterious ways.

For instance, if you want your web server Apache in my case to have access to a directory, that directory and the files and directory contained in it must allow the user or group the web server runs as to be able to access the directory. It is helpful to understand where these files are located and how they are referenced. The bitnami. The user can mod_wsgi multiple applications their application specific configuration files in this file.

My application program runs inference on the AttnGan network. The program performs two tasks. To make the system accessible through a mod_wsgi multiple applications service, a user must be able to call these methods over the internet and pass parameters for example, caption string to the generate function.

This can be achieved using the Flask framework. Here caption and modelname can be user provided strings. Before proceeding further, mod_wsgi multiple applications, you should get the Flask minimal application working and then add the Flask decorators to the relevant functions in your Python code and make sure you are able to call those functions from a web client.

Once your Flask based web service is working locally, the next step is to make it available to Apache, which will in turn make it internet accessible. My application set mod_wsgi multiple applications looks like this:.

This can be done by creating a httpd-app, mod_wsgi multiple applications. To tell Apache about httpd-app. Next up is setting up your server so that your client can access it via Apache.

This is fairly easy to do. Follow directions here. On a Bitnami installation, mod_wsgi multiple applications, the location of the Apache apxs file will be different, so your configure command will look like:. Next step is to create a configuration for WSGI, mod_wsgi multiple applications. This looks like the following on my set up attngan-wsgi-config. There are two ways to run WSGI applications. In this mode the application will be hosted within the Apache worker processes used to handle normal static file requests, mod_wsgi multiple applications.

In this mode, mod_wsgi multiple applications, a set of processes is created for hosting a WSGI application, mod_wsgi multiple applications, with any requests for that WSGI application automatically being routed to those processes for handling. This is better as if you make changes to your python code, those can automatically be mod_wsgi multiple applications up by Apache without having to restart the server.

The first argument is the path to your python server file, second option python-path adds your site-packages folder to the WSGI python path. This is needed because many of the Python packages are installed in. The options specify how many processes and threads to launch, mod_wsgi multiple applications. This should be the output of running.

See WSGI configuration guide for details. This imposes restrictions on where this WSGI configuration file can be placed in the various Apache configuration files. In my setup, I placed the configuration file with the directives shown above directly at the bottom of mod_wsgi multiple applications httpd. Note that there is no requirement that the WSGI directives be in one file. You mod_wsgi multiple applications free to split them up as you wish. I put them all in one file to make it easier to keep track.

Now for the content of the WSGI application file. The job of this file is to define the application object that will serve as the entry point of your Python application. This file obtains the Python version and prefix and returns that information after wrapping it into a HTTP header, mod_wsgi multiple applications. Before you run this, mod_wsgi multiple applications, you should make sure that Apache has the right permissions to access the folder where your server files are located.

The easiest way to do this is to change the group of your server directory and its contents to the group Apache runs as daemon in my case using chgrp and then make sure the group has the right permissions. For setting the permissions, mod_wsgi multiple applications, I simply copied the permissions from another folder that Apache had access to my server folder.

This can be done using the chmod —reference option. If everything matches, you should be good to go. Now you can replace the content of your wsgi file with something like the following:. This setup works, but is a bit cumbersome to mod_wsgi multiple applications up and tough to debug. The outputs of my print statements in the Python file are sent to the Apache log files instead of being printed to the console which makes debugging more difficult.

I was also having some memory issues where the memory consumption after each HTTP request was increasing and causing the system to freeze. I will now describe the second method which I found much easier to set up. In this approach, your application endpoint is directly visible to the mod_wsgi multiple applications. See this for a very nice description of how this works and this for a simple example of how to set this up.

The picture before describes the difference between the two approaches. The above snippet can be placed in one of your Apache config files. I placed it at the end of the bitnami-apps-prefix. The reverse proxy mechanism also allows you to set up load balancing, where you run multiple servers and tell Apache about these servers using the BalancerMember directive. The Flask development server is not intended for use in production.

It is not designed mod_wsgi multiple applications be particularly efficient, stable, or secure. This brings us to gunicorn, mod_wsgi multiple applications.

Launching gunicorn is very simple:. The first argument is the location of the gunicorn configuration file. In my setup, the gunicorn. The second argument is the URL and port where I want my servers to listen. This should match the value you specify in the ProxyPass directive in your Apache config. The third argument wsgi is the name of the python file that contains the wsgi application code.

My wsgi. Mod_wsgi multiple applications third argument is the number of processes that gunicorn should launch and the last argument assigns a name to those processes so it is easier to find them in the output of ps or htop.

The idea is that with multiple processes running, concurrent requests can be distributed across available processes, making your application more responsive. Selecting the model causes the init function in Python to be called, where the word encoding and the attention GAN models are loaded. Hitting generate calls the generate function in Python where the loaded models are used.

If the number of workers is more than 1, it is possible that gunicorn will call init in one process and generate in another one. This will create a problem as the process that runs generate will not have the model loaded in its memory. You can see which process runs a function using the os. The problem can be easily solved by calling init with all available models in your wsgi. That way all the models will be loaded at application startup and available when generate is called.

Now mod_wsgi multiple applications can specify more than one workers without any issues. This will use more Mod_wsgi multiple applications though as each worker process will load both models. You can see the total memory consumption using the Linux htop utility. Save my name, email, and website in this browser for the next time I comment.

 

Deploying multiple django apps on Apache with mod_wsgi - Stack Overflow

 

mod_wsgi multiple applications

 

Also here's the carlosguadian.tk file for both applications. import os import sys path = '/var/www/py/site1' if path not in carlosguadian.tk: carlosguadian.tk(path) carlosguadian.tkault("DJANGO_SETTINGS_MODULE", "carlosguadian.tkgs") from carlosguadian.tk import get_wsgi_application application = get_wsgi_application() Now, here's my problem. Multiple mod_wsgi apps on one virtual host directing to wrong app. Effectively, for any given number of worker processes, it cycles through the total number of them sending the request to whichever one it hit first regardless of the WSGIScriptAlias directive. No matter what I do (setting WSGIProcessGroup, daemon mode vs. What is the alternative solution to support multiple wsgi applications then? If you have more than one WSGI application, then you simply need to create multiple mod_wsgi daemon process groups and delegate each WSGI application to run in its own daemon process group. With that done you can then happily set WSGIApplicationGroup to %{GLOBAL} for both.