DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD Packages and Ports

OpenBSD Packages and Ports Installation and upgrading of packages and ports on OpenBSD.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 31st July 2024
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 67
Default Debugging httpd-gunicorn.sock

Dear Users,

TL,DR; I tried to run my flask app by using Gunicorn and httpd. Socket renders page with "curl -v --unix-socket /var/www/run/gunicorn.sock http://localhost/" but when you hit the server you got 500 error.

httpd.conf:
Code:
prefork 3

server "www.example.com" {
	listen on * port 80
	location "/*" {
		fastcgi socket "/var/www/run/gunicorn.sock"
		root "cython_test"
	}
}

types {
	include "/usr/share/misc/mime.types"
}
-this cython_test folder is already in /var/www
-I checked the httpd logs and it says:
Code:
server www.example.com, client 1 (1 active), ip_addr_of_client:63074 -> ip_addr_of_server, No such file or directory (500 Internal Server Error)
-I checked /var/www/run and yes "gunicorn.sock" exist when I start gunicorn.

How can I debug the connection between httpd and gunicorn?
Reply With Quote
  #2   (View Single Post)  
Old 1st August 2024
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 8,017
Default

To my knowledge, fastcgi socket locations are based off of the httpd(8) chroot, which by default is /var/www. You might try setting the socket to "/run/gunicorn.sock" and see if that makes a difference.

In my php webserver, I use:
Code:
location "*.php" {
    fastcgi socket "/run/php-fpm.sock"
    }
Reply With Quote
  #3   (View Single Post)  
Old 1st August 2024
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 67
Default

Quote:
Originally Posted by jggimi View Post
To my knowledge, fastcgi socket locations are based off of the httpd(8) chroot, which by default is /var/www. You might try setting the socket to "/run/gunicorn.sock" and see if that makes a difference.

In my php webserver, I use:
Code:
location "*.php" {
    fastcgi socket "/run/php-fpm.sock"
    }
Dear jggimi,

Thank you for your input. I tried it with the setting you suggested and the result is 500.

Then I realized maybe my location is wrong. I changed and tried variations of configuration and got a different error code.
Code:
prefork 3

server "www.example.com" {
	listen on * port 80
	location "/cython_test/*" {
                #tried this socket path first then tried the one below
		#fastcgi socket "/var/www/run/gunicorn.sock"
                
                #second socket path
                fastcgi socket "/run/gunicorn.sock"
		
                #these roots are also tried with every socket path variation above
                #root "cython_test"
                root "/"
	}
}

types {
	include "/usr/share/misc/mime.types"
}
Now I'm not getting 500 error. Instead, I'm getting 403 on / and 404 error on specific paths.

this is my /var/www:
Code:
ls -1 /var/www
acme
bin
cache
cgi-bin
conf
cython_test
htdocs
logs
run
Reply With Quote
  #4   (View Single Post)  
Old 1st August 2024
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 8,017
Default

The socket file must be read/write by the httpd(8) daemon user, www. For example, this is from the same PHP webserver, where the socket's owner and group are both www:
Code:
$ ls -ld /var/www/run/
drwxr-xr-x  2 root  daemon  512 Jul 12 20:22 /var/www/run/
$ ls -l /var/www/run/
total 0
srw-rw----  1 www  www  0 Jul 12 20:22 php-fpm.sock
Reply With Quote
  #5   (View Single Post)  
Old 1st August 2024
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 67
Default

I got this when I run gunicorn.

Code:
$ ls -l /var/www/run/
total 0
srwxrwxrwx 1 www www 0 date time gunicorn.sock
srw-rw----   1 www www 0 date time slowcgi.sock
Reply With Quote
  #6   (View Single Post)  
Old 1st August 2024
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,155
Default

When you reload httpd to read the edited httpd.conf, do you see any error messages in the logs?
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
  #7   (View Single Post)  
Old 2nd August 2024
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 67
Default

Dear J65nko,

there is actually an interesting thing in here.

Both, access.log and error.log files produced different results after I did the changes above.

At first
my acces.log looks like this:
Code:
www.example.com ip_of_client - - [DateTime] "GET / HTTP/1.1" 500 0
www.example.com ip_of_client - - [DateTime] "GET /favicon.ico HTTP/1.1" 500 0
and error.log looks like this:
Code:
server www.example.com, client 1 (1 active), ip_of_client -> ip_of_server, No such file or directory (500 Internal Server Error)
In the access.log, there is something called favicon.ico, and since this is a Flask application, it gave me the hint that we actually hit the correct location.

after I made aforementioned change (location to /cython_test instead of /*), I got this
access.log:
Code:
www.example.com  ip_of_client - - [DateTime] "GET / HTTP/1.1" 403 0
www.example.com  ip_of_client - - [DateTime] "GET /login HTTP/1.1" 404 0
error.log
Code:
server www.example.com, client 1 (1 active), ip_of_client -> ip_of_server, /index.html (403 Forbidden)
server www.example.com, client 1 (1 active), ip_of_client -> ip_of_server, /login (404 Not Found)
Reply With Quote
  #8   (View Single Post)  
Old 6th August 2024
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 67
Default

Hi again,

I was fixing the dependency issues related to the project. I'm trying to funnel the issues to pinpoint the main problem.

Could you guys please give me a hint about permitions?
So far I have a
1-)project folder inside /var/www,
2-) inside of the project folder, there is a sqlite database file which I should write and read.
3-)inside of the project folder, there is a python virtual environment folder where I run the binaries such as gunicorn etc.
4-) Also the /var/www/run/gunicorn.sock socket.
How should I handle chown's and chmod's for them?
Reply With Quote
  #9   (View Single Post)  
Old 6th August 2024
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,155
Default

I don't know anything about FLASK and Gunicorn, but I wonder why you want to install all that stuff (including a SQLite database) inside /var/www

Starting with the last item, the database:
A database like MySQ/MariaDB can be configured to use a 127.0.0.x loopback or a local socket. There is no need for the database files nor its binaries to be inside /var/www at all.

If I read https://flask.palletsprojects.com/en...ploying/nginx/ it should be quite easy to run FLASK apps. Remember that the OpenBSD httpd webserver configuration is rather nginx-like.

I may be wrong, but aren't you complicating things?
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
Old 7th August 2024
gordon.f gordon.f is offline
Fdisk Soldier
 
Join Date: Oct 2021
Location: Europe
Posts: 67
Default

Dear J65nko,

Thanks for the input. Yes, I wanted to go with OpenBSD base tools and now I understand it is complicated for me at least.

The SQLite choice was for demonstration purposes. For the production, I decided to use MariaDB.

Thanks for the suggesting nginx, I already knew nginx was out there but I wanted to make it with httpd.

Anyways, thanks for helping me so far. If I come up with a solution, I'll post it in here.
Best regards.
Reply With Quote
Old 4 Weeks Ago
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,155
Default

I did not want you to switch to nginx. I just wanted to point out that the configuration could be simple. OpenBSD's native httpd is fine.

Nginx used to be in OpenBSD base. Later on it was replaced by httpd that was written from scratch by Reyk Floeter. He decided to use a configuration file with directives that closely resembled the nginx.conf file

You could start by getting httpd working with some simple static html pages. Then switch to some simple PHP pages and get that working. There are a lot of tutorials out there that can help you out with that. This will help you to understand how the database, the webserver and PHP work together.

Then bring in the stuff like Flask that you really want to work with.
Cannot SQLite work with a local socket?

https://www.sqlite.org/whentouse.html is very helpful in deciding whether you need a heavier database engine like MariaDB of MySQL.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
OpenSMTP / Dovecot Debugging smh1 OpenBSD Packages and Ports 2 29th October 2021 11:34 AM
Automating the "vi /etc/httpd.conf", httpd -n, rcctl restart httpd" treadmill J65nko Guides 0 18th May 2021 12:58 AM
New httpd and PHP morophla OpenBSD Packages and Ports 21 31st August 2015 09:54 PM
Debugging random restarts backrow OpenBSD General 5 21st March 2011 04:58 AM
Remote debugging Linux kernel Mr-Biscuit Other BSD and UNIX/UNIX-like 0 11th December 2008 04:46 AM


All times are GMT. The time now is 06:52 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick