DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 22nd February 2015
hanzer's Avatar
hanzer hanzer is offline
Real Name: Adam Jensen
just passing through
 
Join Date: Oct 2013
Location: EST USA
Posts: 314
Default httpd fastcgi configuration and programming

I'm playing with the httpd(8) daemon (in 5.6-stable) but I'm a n00b to web tech and there isn't much information [that I've found] for OpenBSD's (new?) httpd other than the two brief man pages - (the other being httpd.conf(5)).

The man page says: "The FastCGI implementation has optional socket support". (Is there a way to use FastCGI without sockets?) Anyway, I am totally without a clue. Let's say I want to write a little C language FastCGI web application (something like a Hello, World program) as a way to begin to understand the overall architecture and configuration of the tech. Does anyone know how to do this?

My current configuration is dead simple. /etc/httpd.conf is:
Code:
prefork 1
server "default" { 
        listen on 192.168.0.1 port 80 
}
And /var/www/htdocs/index.html is reachable from browsers on my LAN.

If the configuration is modified to:
Code:
prefork 1
fastcgi
server "default" { 
        listen on 192.168.0.1 port 80 
}
Then $ sudo httpd -n returns: "/etc/httpd.conf:2: syntax error"

I found the www/fcgi port and an example tiny-fcgi.c but there's no mention of sockets anywhere anywhere in the code and after compiling it, I don't know what to do next. I'm such a newb, I need serious schooling. Any ideas?
Reply With Quote
  #2   (View Single Post)  
Old 22nd February 2015
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,977
Default

It is my understanding that the syntax is either "no fastcgi" or "fastcgi socket <file>"

For example, to use php-fpm with httpd, use something like (depending on your php-fpm.conf file):
Code:
 location "*.php" 
{  fastcgi socket "/run/php-fpm.sock"}
Disclaimer: I use fastcgi and php-fpm with nginx currently, rather than with httpd. I'm also using loopback rather than filesystem sockets.
Reply With Quote
  #3   (View Single Post)  
Old 23rd February 2015
hanzer's Avatar
hanzer hanzer is offline
Real Name: Adam Jensen
just passing through
 
Join Date: Oct 2013
Location: EST USA
Posts: 314
Default

Quote:
Originally Posted by jggimi View Post
I'm also using loopback rather than filesystem sockets.
If you have nginx and php running on the same machine then Unix-domain sockets would probably be more efficient than IP sockets.

unix domain sockets vs. internet sockets

What seems nifty with the IP socket approach is the web app can be migrated to a machine other than the one on which the web server is running.

OpenBSD's httpd manpage has no mention of configuring FastCGI to use IP sockets (AF_INET) but only Unix-domain sockets (AF_UNIX). However, the source (/usr/src/usr.sbin/httpd/server_fcgi.c) seems to suggest that IP sockets are possible [possibly ].

Side note: I figured out why the default AF_UNIX file for fastcgi is set to /run/slowcgi.sock. There is a FastCGI to CGI wrapper server - slowcgi(8) - in the base system that uses that socket and, from what I've seen so far, seems to work fairly seamlessly with httpd.

But, alas, committed to figuring out web programming, I currently find myself eyeballs deep in the FastCGI Specification. Oh, the humanity!
Reply With Quote
  #4   (View Single Post)  
Old 23rd February 2015
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,977
Default

Quote:
Originally Posted by hanzer View Post
If you have nginx and php running on the same machine then Unix-domain sockets would probably be more efficient than IP sockets.
Yes, I know, I've used Unix sockets with nginx before. I believe when I set it up the web server and the application server were separate machines. They are currently the same platform, and I could switch.
Reply With Quote
  #5   (View Single Post)  
Old 22nd February 2015
hanzer's Avatar
hanzer hanzer is offline
Real Name: Adam Jensen
just passing through
 
Join Date: Oct 2013
Location: EST USA
Posts: 314
Default

"[no] fastcgi [socket socket]"
"socket" seems to be an optional override of the default location /run/slowcgi.sock.

But whether or not to use fastcgi is configured on a per server basis, so maybe the correct syntax for my /etc/httpd.conf is:
Code:
prefork 1
server "default" { 
        listen on 192.168.0.1 port 80 
        fastcgi
}
Now, $ sudo httpd -n returns: "configuration OK"

Groovy. Thanks for the hint, jggimi! One step closer...
Reply With Quote
  #6   (View Single Post)  
Old 23rd February 2015
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,977
Default

And this, regarding the development of slowcgi(8).
Reply With Quote
  #7   (View Single Post)  
Old 23rd February 2015
hanzer's Avatar
hanzer hanzer is offline
Real Name: Adam Jensen
just passing through
 
Join Date: Oct 2013
Location: EST USA
Posts: 314
Default

Quote:
Originally Posted by jggimi View Post
Yes, I know, ...
I know you know. But you didn't seem to know that I know you know.

Quote:
Originally Posted by jggimi View Post
And this, regarding the development of slowcgi(8).
I still haven't gotten past my negatively colored opinion of naddy (due to The Terrible mkdir Tragedy of 2013).
Reply With Quote
  #8   (View Single Post)  
Old 24th February 2015
hanzer's Avatar
hanzer hanzer is offline
Real Name: Adam Jensen
just passing through
 
Join Date: Oct 2013
Location: EST USA
Posts: 314
Default another step closer

This configuration seems to work: /etc/httpd.conf
Code:
server "default" { 
        listen on 192.168.0.1 port 80 
        location "/*" {
                fastcgi socket "/run/test.sock"
        }
}
$ sudo nc -lU /var/www/run/test.sock

As does this: /etc/httpd.conf
Code:
server "default" { 
        listen on 192.168.0.1 port 80 
        location "/*" {
                fastcgi socket ":8080"
        }
}
$ nc -l 127.0.0.1 8080

I haven't [yet] figured out how to specify an IP address for the AF_INET socket approach...
Reply With Quote
  #9   (View Single Post)  
Old 26th February 2015
xJohansenx xJohansenx is offline
New User
 
Join Date: Dec 2014
Location: Ottawa, Ontario, Canada
Posts: 6
Default

Hi hanzer,

Would it be possible to see your /etc/php-fpm.conf file as I'm curious as to how you managed to make fastcgi work. It seems that I'm missing something... and it's probably just in front of me.

Thanks,

Joh
Reply With Quote
Old 26th February 2015
hanzer's Avatar
hanzer hanzer is offline
Real Name: Adam Jensen
just passing through
 
Join Date: Oct 2013
Location: EST USA
Posts: 314
Default

Quote:
Originally Posted by xJohansenx View Post
Would it be possible to see your /etc/php-fpm.conf file as I'm curious as to how you managed to make fastcgi work. It seems that I'm missing something... and it's probably just in front of me.
Wish I could help but I'm not using php-fpm [yet]. For now, I am only exploring fastcgi (API/protocol) through the socket in an attempt to develop a basic understanding of the tech. The immediate goal is to write a little C language daemon that will process requests and generate simple HTML responses (a modest goal but, amidst my countless other projects, progress is slow).

jggimi might be able to chime in with a hint for you.
Reply With Quote
Old 27th February 2015
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,977
Default

Here's my php directive in nginx.conf I use on my net/nfsen server:
Code:
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /var/www/htdocs/nfsen;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_param  HTTPS on;

        }
And, here's my complete php-fpm.conf, used for multiple virtual servers in nginx:
Code:
[global]
[www]
user = www
group = www

listen = 127.0.0.1:9000

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

chroot = /var/www

Last edited by jggimi; 27th February 2015 at 12:35 AM. Reason: typographic (columns in code block)
Reply With Quote
Old 27th February 2015
xJohansenx xJohansenx is offline
New User
 
Join Date: Dec 2014
Location: Ottawa, Ontario, Canada
Posts: 6
Default

Thanks jggimi for that example! I was able to make it work based on what you provided.
Reply With Quote
Reply

Tags
httpd, httpd fastcgi, nginx, php-fpm.conf

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
httpd in OpenBSD 5.6 jorisvh OpenBSD Packages and Ports 8 4th November 2014 12:14 AM
php 5.3 fastcgi Fekete OpenBSD Packages and Ports 5 16th July 2013 11:59 PM
httpd problem or something else c0mrade Other BSD and UNIX/UNIX-like 6 15th January 2009 09:19 PM
httpd -DNOHTTPACCEPT starbuck FreeBSD General 9 23rd August 2008 12:14 PM
httpd.conf Snoop1990 General software and network 5 29th July 2008 04:30 AM


All times are GMT. The time now is 04:44 PM.


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