How to execute WSGI file with Dynamic content in Apache
To execute WSGI file with Dynamic content in Apache
WSGI is an internet standard based on Python and is used as an interface between the web server and the application you intend to run. Through this article you will learn the method to execute WSGI Python file in dynamic webpage content in apache webserver on your CentOS machine.
Prerequisites
Executing a WSGI file requires prior installation of Apache service as it is very vital for the process.
To execute WSGI file
Make sure you have the mod_wsgi package installed in your machine. Use the following command for the same purpose.
[root@server1 Desktop]# yum install mod_wsgi* -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.fibergrid.in
* extras: mirror.fibergrid.in
.
.
.
Installed:
mod_wsgi.x86_64 0:3.4-12.el7_0
Complete!
Now that mod_wsgi is installed, create a directory under document root as follows in which you should move wsgi script file.
[root@localhost Desktop]# mkdir /var/www/dynamic
Run the following command to move wsgi script file into the new directory.
[root@localhost Desktop]# mv scripts.wsgi /var/www/dynamic/
Set the selinux context for that script file location as it adds additional information such as user, role, type, and a level to that file. Use the following command.
[root@localhost Desktop]# semanage fcontext -a -t httpd_sys_script_exec_t ' /var/www/dynamic(/.*)?'
Once thes elinux context is set, restore the selinux configuration using restorecon command as follows.
[root@localhost Desktop]# restorecon -Rc /var/www/dynamic/scripts.wsgi
restorecon reset /var/www/dynamic/scripts.wsgi context unconfined_u:object_r:admin_home_t:s0-> unconfined_u:object_r:httpd_sys_script_exec_t:s0
Once it is done, configure the VirtualHost by creating a file in apache conf.d location and configure it as follows.
[root@localhost Desktop]# vim /etc/httpd/conf.d/wsgi.conf
listen 8086
< virtualhost *:8086>
servername server1.example.com
documentroot /var/www/dynamic
WSGIScriptAlias / /var/www/dynamic/scripts.wsgi
< /virtualhost>
And then, configure selinux context for newly created port as follows.
[root@localhost Desktop]# semanage port -a -t http_port_t -p tcp 8086
Once it is done, add the port into firewall and reload service as follows.
[root@localhost Desktop]# firewall-cmd --permanent --add-port=8086/tcp
[root@localhost Desktop]# firewall-cmd &ndash reload
Check the apache syntax using below command.
[root@localhost Desktop]# httpd &ndash t
Finally, restart the apache service so that the process to take effect.
[root@localhost Desktop]# systemctl restart httpd.service
Open the browser and enter your server name with dynamic port number.
Now you see the wsgi file output.
Executing WSGI was quite simple, isn' t it? WSGI files are very useful as they specify the way in which web applications can be chained together to process one request.
Comments ( 0 )
No comments available