0

I'm running CentOS 8.1 with Python 3.6.8, and Apache/2.4.37.

I'm new to mod_wsgi. I found this "hello world" example and got it to work:

https://www.ionos.com/community/hosting/python/use-mod-wsgi-to-run-python-as-a-web-application-on-centos-7/

The problem I'm having is that this appears to require each .py file to be added to its own .conf file to be added to conf.d, as seen in /etc/httpd/conf.d/helloworld.conf:

WSGIScriptAlias /helloworld /var/www/python/helloworld.py <Directory /var/www/python/> Order allow,deny Allow from all </Directory> 

And to run on python (.py) scripts out of /var/www/python.

This is very inconvenient before it looks like each Python program needs to be hardcoded instead of running out of the /var/www/html directories. We have development in Python 2 where the .py files are executed in the same directory along with .html and .php files. Under CentOS 7 we just had an entry added to the httpd.conf to recognize all .py files and make sure they got executed by Python.

I see the author mentioned this was for security. Is there a way to do this still being secure, but so I don't have to gather up all the .py files on the server and make .conf files for it, as seen in this "hello world" example?

If my take on using mod_wsgi is completely wrong, please enlighten me.

1 Answer 1

0

The mod_wsgi also has WSGIScriptAliasMatch that could be useful in your case, e.g.

WSGIScriptAliasMatch ^/([^/]+).py /var/www/python/$1.py 

If you don't require the shorter paths, you could also use WSGIScriptAlias for the whole folder:

WSGIScriptAlias /python/ /var/www/python/ 

That would be equivalent to:

Alias /python/ /var/www/python/ <Location /python> SetHandler wsgi-script Options +ExecCGI </Location> 

This is similar to how you'd use mod_python's Publisher Handler:

<Directory /var/www/python> AddHandler mod_python .py PythonHandler mod_python.publisher PythonDebug On </Directory> 

For more examples, please refer to mod_wsgi Configuration Guidelines

2
  • How would I do this so any .py file located anywhere within the directories in /var/www/html would execute the .py file just as it executes any .php file no matter where it is in /var/www/html? Commented Mar 15, 2020 at 20:10
  • How about AddHandler wsgi-script .py? I really suggest reading the documentation. Commented Mar 16, 2020 at 3:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.