Re: Flask app as UWSGI returning 500 when accessed through OpenBSD HTTPD

2017-10-19 Thread Kamil Cholewiński
I Am Not A uWSGI Expert, but the way we've been usually setting it up is
via plain HTTP reverse proxying, never CGI/FastCGI. I would try that
approach first.



Re: Flask app as UWSGI returning 500 when accessed through OpenBSD HTTPD

2017-10-18 Thread Ajitabh Pandey
On Wed, Oct 18, 2017 at 7:25 PM, Ajitabh Pandey 
wrote:

>
> On Wed, Oct 18, 2017 at 7:14 PM, Jiri B  wrote:
>
>> On Wed, Oct 18, 2017 at 06:55:32PM +0530, Ajitabh Pandey wrote:
>> > On Wed, Oct 18, 2017 at 1:43 PM, Jiri B  wrote:
>> >
>> > > On Wed, Oct 18, 2017 at 01:40:06PM +0530, Ajitabh Pandey wrote:
>>
>> See?
>
>
> Yes, I see that. Thank you very much. I will try and figure out on how do
> I make uwsgi create socket with specific ownership and permissions. I would
> hate to chroot the uwsgi because that would mean to copy python libraries
> in /var/www :-)
>
> Thanks again for inputs here.
>

I am now able to create the socket with correct permission / ownership.
Here is the uwsgi ini file -

[uwsgi]
module = wsgi
# process related settings
master = 1
processes = 4
threads = 2

socket = /var/www/run/hello.sock
# approprite ownership and permissions on socket
chmod-socket = 660
chown-socket = www:www

# clear environment on exit
vaccume = true
wsgi-file = myproject.py

and I am running it as -

$ doas uwsgi --ini hellopy.ini --callable app

and this is the permissions now -

$ ls -l /var/www/run
total 0
srw-rw  1 www  www  0 Oct 18 19:47 hello.sock=

Now when I access

http://192.168.1.111/hello/

request just times out (return code 408)

access.log just shows -

default x.y.a.b - - [18/Oct/2017:19:48:41 +0530]" " 408 0

There is nothing in error.log

Any idea what am I doing wrong.

Regards.
-- 
Ajitabh Pandey
http://ajitabhpandey.info/


Re: Flask app as UWSGI returning 500 when accessed through OpenBSD HTTPD

2017-10-18 Thread Ajitabh Pandey
On Wed, Oct 18, 2017 at 7:14 PM, Jiri B  wrote:

> On Wed, Oct 18, 2017 at 06:55:32PM +0530, Ajitabh Pandey wrote:
> > On Wed, Oct 18, 2017 at 1:43 PM, Jiri B  wrote:
> >
> > > On Wed, Oct 18, 2017 at 01:40:06PM +0530, Ajitabh Pandey wrote:
> > >
> > > Can httpd access the socket? What are permissions?
> >
> > Here are the perms -
> >
> > srwxr-xr-x  1 root  daemon  0 Oct 18 13:35 hello.sock
>
> And voila, they are wrong. How would httpd daemon be able
> to write there?
>
> See what slowcgi, a fastcgi->cgi daemon says about socket:
>
>   slowcgi opens a socket at /var/www/run/slowcgi.sock, owned by www:www,
>   with permissions 0660.  It will then chroot(8) to /var/www and drop
>   privileges to user "www".
>
> See?
>


Yes, I see that. Thank you very much. I will try and figure out on how do I
make uwsgi create socket with specific ownership and permissions. I would
hate to chroot the uwsgi because that would mean to copy python libraries
in /var/www :-)

Thanks again for inputs here.
-- 
Ajitabh Pandey
http://ajitabhpandey.info/


Re: Flask app as UWSGI returning 500 when accessed through OpenBSD HTTPD

2017-10-18 Thread Jiri B
On Wed, Oct 18, 2017 at 06:55:32PM +0530, Ajitabh Pandey wrote:
> On Wed, Oct 18, 2017 at 1:43 PM, Jiri B  wrote:
> 
> > On Wed, Oct 18, 2017 at 01:40:06PM +0530, Ajitabh Pandey wrote:
> >
> > Can httpd access the socket? What are permissions?
> >
> > j.
> >
> 
> Here are the perms -
> 
> srwxr-xr-x  1 root  daemon  0 Oct 18 13:35 hello.sock

And voila, they are wrong. How would httpd daemon be able
to write there?

See what slowcgi, a fastcgi->cgi daemon says about socket:

  slowcgi opens a socket at /var/www/run/slowcgi.sock, owned by www:www,
  with permissions 0660.  It will then chroot(8) to /var/www and drop
  privileges to user "www".

See?

j.



Re: Flask app as UWSGI returning 500 when accessed through OpenBSD HTTPD

2017-10-18 Thread Ajitabh Pandey
On Wed, Oct 18, 2017 at 1:43 PM, Jiri B  wrote:

> On Wed, Oct 18, 2017 at 01:40:06PM +0530, Ajitabh Pandey wrote:
>
> Can httpd access the socket? What are permissions?
>
> j.
>

Here are the perms -

srwxr-xr-x  1 root  daemon  0 Oct 18 13:35 hello.sock

-- 
Ajitabh Pandey
http://ajitabhpandey.info/


Re: Flask app as UWSGI returning 500 when accessed through OpenBSD HTTPD

2017-10-18 Thread Ajitabh Pandey
On Wed, 18 Oct 2017 at 4:45 PM, Gregory Edigarov  wrote:

> >
> > I get 500
> >
> hi, what's in your error.log?


Nothing is in the error log. The access log indicates one line with 500 in
it.


Re: Flask app as UWSGI returning 500 when accessed through OpenBSD HTTPD

2017-10-18 Thread Gregory Edigarov

On 18.10.17 10:36, Ajitabh Pandey wrote:

$ uwsgi --http : --wsgi-file myproject.py --master --callable app

$ curl http://127.0.0.1:/

returns the contents, but when I access the page as

http://192.168.1.111/hello/

I get 500.

Any pointers will be helpful.


hi, what's in your error.log?



Re: Flask app as UWSGI returning 500 when accessed through OpenBSD HTTPD

2017-10-18 Thread Jiri B
On Wed, Oct 18, 2017 at 01:40:06PM +0530, Ajitabh Pandey wrote:
> Thanks for the quick response. I tried that, still getting 500 the same
> problem -
> 
> $ doas uwsgi --socket /var/www/run/hello.sock --wsgi-file myproject.py
> --master --callable app
> 
> In /etc/httpd.conf -
> 
>   location "/hello/*" {
> fastcgi socket "/run/hello.sock"
>   }

Can httpd access the socket? What are permissions?

j.



Re: Flask app as UWSGI returning 500 when accessed through OpenBSD HTTPD

2017-10-18 Thread Ajitabh Pandey
Thanks for the quick response. I tried that, still getting 500 the same
problem -

$ doas uwsgi --socket /var/www/run/hello.sock --wsgi-file myproject.py
--master --callable app

In /etc/httpd.conf -

  location "/hello/*" {
fastcgi socket "/run/hello.sock"
  }

Regards.
-- 
Ajitabh Pandey


On Wed, Oct 18, 2017 at 1:22 PM, Kim Zeitler 
wrote:

> Hi
>
> you have a slight error, fastcgi wants a socket not a port.
>
> On 10/18/17 09:36, Ajitabh Pandey wrote:
>
>> Hi,
>>
>> I am trying to setup a sample flask application proxy through OpenBSD
>> httpd. Here is the config -
>>
>> --
>> ext_ip="192.168.1.111"
>>
>> prefork 2
>>
>> server "default" {
>>listen on $ext_ip port 80
>>root "/htdocs"
>>
>>location "/hello/*" {
>>  fastcgi socket ":"
>>}
>>
>
> from httpd.conf(5)
> ...
> Enable FastCGI instead of serving files.  The socket is a local
>  path name within the chroot(2) root directory of httpd(8) and
>  defaults to /run/slowcgi.sock.
> ...
>
> Try running uwsgi with a socket in /var/www/run instead of an tcp port
>
>
> --
> Kim Zeitler
> Bachelor of Science (Hons)
>
> Konzept Informationssysteme GmbH
> Am Weiher 13 • 88709 Meersburg
>
> Fon: +49 7532 4466-240
> Fax: +49 7532 4466-66
> kim.zeit...@konzept-is.de
> www.konzept-is.de
>
> Amtsgericht Freiburg 581491 • Geschäftsführer: Dr. Peer Griebel,
> Frank Häßler, Dr. Christophe Schoenenberger
>
>


-- 
Ajitabh Pandey
http://ajitabhpandey.info/ | http://unixclinic.net/ |
http://buddingthoughts.info
ICQ - 150615062
Registered Linux User - 240748


Flask app as UWSGI returning 500 when accessed through OpenBSD HTTPD

2017-10-18 Thread Ajitabh Pandey
Hi,

I am trying to setup a sample flask application proxy through OpenBSD
httpd. Here is the config -

--
ext_ip="192.168.1.111"

prefork 2

server "default" {
  listen on $ext_ip port 80
  root "/htdocs"

  location "/hello/*" {
fastcgi socket ":"
  }
}

types {
  text/csscss
  text/html   html htm
  text/plain  txt
  image/gif   gif
  image/jpeg  jpeg jpg
  image/png   png
  application/javascript  js
  application/xml xml
}
--

The flask app is

--
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
return "Hello There!"

if __name__ == "__main__":
app.run(host='127.0.0.1')

I am running UWSGI as -
--

$ uwsgi --http : --wsgi-file myproject.py --master --callable app

$ curl http://127.0.0.1:/

returns the contents, but when I access the page as

http://192.168.1.111/hello/

I get 500.

Any pointers will be helpful.

Regards.
-- 
Ajitabh Pandey
http://ajitabhpandey.info/