Flask wsgi app cannot work with WSGI Module

Issues related to applications and software problems
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/05 06:38:40

NikosThess wrote:
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/
1. Remove the 'I' before the Virtualhost.
2. Put '<Directory /home/nikos/>' section outside the Virtualhost section
3. You get 'access denied' due to apache not able to read the app.py .Set permissions of app.py -> 750 apache:apache
4. Stop using '-Z' when selinux is disabled.
5. Once you make it running set SELINUX to permissive and consider switching to ENFORCING

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

Re: Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/05 06:54:12

but the file app.py is owned byh user nikos:nikos and with perms 755.
Even if re-own it to apache user still i get the forbidden error.

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/05 07:17:07

What is happening when you run:

Code: Select all

sudo -u apache /home/nikos/public_html/app.py
Edit:
Move your config for '/home/nikos/public_html' directory above the VirtualHost section.

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

Re: Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/05 11:04:13

Code: Select all

[root@superhost public_html]# sudo -u apache /home/nikos/public_html/app.py
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://superhost.gr:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 150-808-806
Also i have the conf file as follows, wea re talking httpd-vhosts.conf NOT the general httpd.conf file

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

       AllowOverride None
       Require all granted
   </Directory>
</VirtualHost>

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

Re: Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/05 11:14:54

Also a very weird thign is that if a add the following line within my vhost

Code: Select all

ErrorLog /home/nikos/public_html/logs/error.log
and restart Apache, it gives an error that httpd cannot access the file.

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/05 11:46:53

Try modifying the file (not talking of the main config):

Code: Select all

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

       AllowOverride None
       Require all granted
 </Directory>

<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
</VirtualHost>

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

Re: Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/05 11:53:39

I'am still receiving the same test page which you can see when http://superhost.gr

Its like wsgi cant even see my wsgi 'app.py' at all.

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/05 23:07:06

Could you try with:

Code: Select all

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

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

Re: Flask wsgi app cannot work with WSGI Module

Post by NikosThess » 2018/09/06 04:53:40

When i moved the contents form vhosts.conf to httpd.conf it worked right away!! 2 questions.

1. If i put the contents back to vhosts.conf and create a new subdomain like 'nikos.superhost.gr' then i could only access my webpage as 'http://nikos.superhost.gr' ?Becouse i want to access it only as 'http://superhost.gr' nto with subdomain in front

2. I have 3 scripts inside 'public_html'. Is this the right way to configure to run them through mod_wsgi or there is a more general way so i dont have an each line for every script?

Code: Select all

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

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

    AllowOverride None
    Require all granted
</Directory>

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/06 19:41:34

I did not understand point1. Maybe an example would be easier to explaint it.
About point 2 , shouldn't you define your WSGIs in a VirtualHost stanza ? In your case it's looking like no matter which server you call -> you will always request the python WSGIs , and as every virtualhost has a different DocumentRoot, the way you did it is not very nice.

Post Reply