Flask wsgi app cannot work with WSGI Module

Issues related to applications and software problems
NikosThess
Posts: 19
Joined: 2018/05/10 20:36:20

Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/03 18:21:39

Hello, several days now i'm facing the same problem i have installed python36u-mod_wsgi module because mod_wsgi coudl not be isntalled.
I reinstalled anything from scratch but still my wsgi app.py application wont run.
Please help me out. The above is httpd-vhosts.conf as i have configured it.

Code: Select all

<VirtualHost *:80>
    ServerName superhost.gr
    ServerAdmin nikos@superhost.gr

    WSGIDaemonProcess public_html user=nikos group=nikos processes=1 threads=5
    WSGIScriptAlias / /home/nikos/public_html/app.py


    <Directory /home/nikos/public_html>
        WSGIProcessGroup public_html
        WSGIApplicationGroup %{GLOBAL}
        WSGIScriptReloading On 

        Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI

        AllowOverride None
        Require all granted
   </Directory>


    ErrorLog /home/nikos/public_html/logs/error.log
    CustomLog /home/nikos/public_html/logs/requests.log combined
</VirtualHost>
I also inserted in httpd.conf but

LoadModule wsgi_module modules/mod_wsgi.so
Include /etc/httpd/conf/httpd-vhosts.conf

i restarted the web server and http://superhost.gr/

and then still the forbidden error, its like it cannot access my folders althought they are all with perms 755 '/home/nikos/*'

What might be the fault?

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: Flask wsgi app cannot work with WSGI Module

Post by hunter86_bg » 2018/09/04 03:42:57

What is the output of:

Code: Select all

ls -lZ  /home/nikos/public_html/
If you use non-standard location, SELINUX will forbid httpd to access it.

NikosThess
Posts: 19
Joined: 2018/05/10 20:36:20

Re: Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/04 06:11:28

Code: Select all

[root@superhost public_html]# ls -lZ  /home/nikos/public_html/
-rwxr-xr-x nikos nikos ?                                clientele.py
-rwxr-xr-x nikos nikos ?                                downloads.py
drwxr-xr-x nikos nikos ?                                phpmyadmin
drwxr-xr-x nikos nikos ?                                private
-rw-r--r-- nikos nikos ?                                sftp-config.json
drwxr-xr-x nikos nikos ?                                static
drwxr-xr-x nikos nikos ?                                stats
drwxr-xr-x nikos nikos ?                                templates
-rwxr-xr-x nikos nikos ?                                web.py
selinux is disabled. What are those question marks?

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: Flask wsgi app cannot work with WSGI Module

Post by hunter86_bg » 2018/09/04 12:52:52

The questionmark is the missing selinux context.
Change the owner of the files to be 'apache:apache' and test again.
Also run 'apachectl configtest' to verify your settings.

NikosThess
Posts: 19
Joined: 2018/05/10 20:36:20

Re: Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/04 13:31:13

Code: Select all

chown -R apache:apache /home/nikos/*
That's the code i shoudl run? If this is then:

Forbidden
You don't have permission to access / on this server.

NikosThess
Posts: 19
Joined: 2018/05/10 20:36:20

Re: Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/04 17:16:01

Could you please provide me help more quick?
This is troubling me 1 week now, and iam sure its something trivial.
Somehting that prohibits access to Apache to my public folders.

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Flask wsgi app cannot work with WSGI Module

Post by TrevorH » 2018/09/04 17:21:58

Did you tell selinux that you want apache httpd to be allowed to access home directories?

httpd_enable_homedirs --> off
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

NikosThess
Posts: 19
Joined: 2018/05/10 20:36:20

Re: Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/04 18:25:25

Hello Trevor,

SELinux is what gives em trouble here? But i just 2 days ago and it disabled, so how can it impose a forbiden error?

How do i enable this directive you posted?
I just put 'httpd_enable_homedirs' inside my httpd.conf ?

Code: Select all

[root@superhost ~]# getenforce
Disabled

[root@superhost ~]# getsebool httpd_enable_homedirs
getsebool:  SELinux is disabled

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: Flask wsgi app cannot work with WSGI Module

Post by hunter86_bg » 2018/09/04 19:52:57

What about the

Code: Select all

apachectl configtest
Usually to deploy a wsgi you need to do :
1. Install 'mod_wsgi'
Maybe this is your main problem
2. Add a 'WSGIScriptAlias' line to a virtual host definition . Something like:

Code: Select all

WSGIScriptAlias /mypythonapp/ /home/nikos/mypythonapp/app.py
In your case I do not see the '/home/nikos/public_html/app.py' in your '/home/nikos/public_html' folder, so check this out (or fix your config)
3.The app.py should be executable (chomd +x ) for the apache user
Another problem here... Fix this also.
4. If SELINUX is enabled , you need the files to be with context 'httpd_sys_content_t'

NikosThess
Posts: 19
Joined: 2018/05/10 20:36:20

Re: Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/04 20:29:43

Code: Select all

I<VirtualHost *:80>
    ServerName superhost.gr

    WSGIDaemonProcess public_html
    WSGIProcessGroup public_html
    WSGIScriptReloading On

    WSGIScriptAlias / /home/nikos/public_html/app.py

    <Directory /home/nikos/public_html>
        Require all granted
    </Directory>
</VirtualHost>

Code: Select all

[root@superhost public_html]# getsebool httpd_enable_homedirs
getsebool:  SELinux is disabled

[root@superhost public_html]# apachectl configtest
Syntax OK

[root@superhost public_html]# ls -lZ app.py 
-rwxr-xr-x nikos nikos ?     
I still don't understand what is the meaning of '?'
Why am i gettign this damn "You don't have permission to access / on this server"

See for yourself http://superhost.gr/

Post Reply