Lighttpd und FastCGI für meine eigene Web-App einrichten?

13321
Nick

Ich arbeite mit Gentoo Linux und versuche Lighttpd + PHP + FastCGI zum Laufen zu bringen. Ich habe festgestellt, dass Lighttpd keinen FastCGI-Prozessmanager hat. Also solltest du Spawn-Fcgi verwenden. Ich habe Lighttpd und PHP am Laufen. Mein Problem ist, dass ich nicht weiß, wie man spawn-fcgi und lighttpd für meine Web-App einrichtet.

Das habe ich installiert:

  • Lighttpd
  • PHP (mit CGIUSE-Flag)
  • Spawn-Fcgi

Die Anwendung, mit der ich zu kommunizieren versuche, ist nur das Beispiel von fcgi docs tiny.c:

#include <stdio.h> #include <stdlib.h> void main(void) { int count = 0; printf("Content-type: text/html\r\n" "\r\n" "<title>CGI Hello!</title>" "<h1>CGI Hello!</h1>" "Request number %d running on host <i>%s</i>\n", ++count, getenv("SERVER_NAME")); } 

Ich habe es von der Konsole aus kompiliert und arbeite:

nick@blozup ~/zwave $ ./tiny.fcgi  Content-type: text/html <title>FastCGI Hello!</title> <h1>FastCGI Hello!</h1>Request number 1 running on host <i>(null)</i> 

Tragen Sie mit mir hier, ich habe keine Ahnung, was ich mache ...

Zuerst habe ich versucht, das kompilierte tiny.fcgiin einem Web-Verzeichnis zu platzieren ( cgi-bininsbesondere, was nicht funktioniert hat, dann nur im Wurzel-Web-Verzeichnis). Die nächste, die ich bekam, war eine 403 verbotene Fehlermeldung. Ich stellte sicher, dass die Berechtigungen liberal waren, kein Glück.

Nachdem ich mehr gelesen hatte, wurde mir klar, dass ich Spawn-Fcgi benutzen musste. Also habe ich es installiert und meine Anwendung verlinkt, die Standardkonfiguration kopiert und für meine Anwendung bearbeitet:

ln -s /etc/init.d/spawn-fcgi /etc/init.d/spawn-fcgi.fcgi cp /etc/conf.d/spawn-fcgi /etc/conf.d/spawn-fcgi.fcgi 

Datei /etc/conf.d/spawn-fcgi.fcgi:

# Copyright 1999-2009 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/www-servers/spawn-fcgi/files/spawn-fcgi.confd,v 1.6 2009/09/28 08:38:02 bangert Exp $  # DO NOT MODIFY THIS FILE DIRECTLY! CREATE A COPY AND MODIFY THAT INSTEAD!  # The FCGI process can be made available through a filesystem socket or # through a inet socket. One and only one of the two types must be choosen. # Default is the inet socket.  # The filename specified by # FCGI_SOCKET will be suffixed with a number for each child process, for # example, fcgi.socket-1. # Leave empty to use an IP socket (default). See below. Enabling this, # disables the IP socket. # FCGI_SOCKET=/var/run/fcgi.socket  # When using FCGI_PORT, connections will only be accepted from the following # address. The default is 127.0.0.1. Use 0.0.0.0 to bind to all addresses. # FCGI_ADDRESS=127.0.0.1  # The port specified by FCGI_PORT is the port used # by the first child process. If this is set to 1234 then subsequent child # processes will use 1235, 1236, etc. # #FCGI_PORT=1234  # The path to your FastCGI application. These sometimes carry the .fcgi # extension but not always. For PHP, you should usually point this to # /usr/bin/php-cgi. # #FCGI_PROGRAM=/usr/bin/php-cgi FCGI_PROGRAM=/home/nick/zwave/tiny.fcgi  # The number of child processes to spawn. The default is 1. # FCGI_CHILDREN=1  # If you want to run your application inside a chroot then specify the # directory here. Leave this blank otherwise. # FCGI_CHROOT=  # If you want to run your application from a specific directiory specify # it here. Leave this blank otherwise. # FCGI_CHDIR=  # The user and group to run your application as. If you do not specify these, # the application will be run as root:root. # FCGI_USER= FCGI_GROUP=  # Additional options you might want to pass to spawn-fcgi # #FCGI_EXTRA_OPTIONS=  # If your application requires additional environment variables, you may # specify them here. See PHP example below. # ALLOWED_ENV="PATH" 

Dann habe ich den Prozess gestartet und es läuft jetzt:

blozup zwave # /etc/init.d/spawn-fcgi.fcgi start Starting.... [OK] blozup zwave # ps aux | grep tiny root 5809 0.0 0.0 2236 504 ? Ss 17:47 0:00 /home/nick/zwave/tiny.fcgi 

und ein Socket wurde erstellt an: /var/run/lighttpd/tiny.socket-1

Was jetzt?

Wie bekomme ich Lighttpd, um eine Verbindung zu diesem herzustellen? und wie kann ich von einer URL darauf zugreifen?

Ich weiß, dass Lighttpd diesen Socket verwenden muss, aber wenn ich die mod_fastcgi.confDatei bearbeite :

fastcgi.server += (".fcgi" => ( "localhost" => ( "socket" => "/var/run/lighttpd/fcgi.socket-1", "bin-path" => "/usr/bin/cgi-fcgi", "max-procs" => 1 )) ) 

Ich erhalte diesen Fehler:

2012-06-13 18:50:18: (mod_fastcgi.c.1389) --- fastcgi spawning port: 0 socket /var/run/lighttpd/fcgi.socket-1 current: 0 / 1 2012-06-13 18:50:18: (mod_fastcgi.c.1103) the fastcgi-backend /usr/bin/cgi-fcgi failed to start: 2012-06-13 18:50:18: (mod_fastcgi.c.1107) child exited with status 1 /usr/bin/cgi-fcgi 2012-06-13 18:50:18: (mod_fastcgi.c.1110) If you're trying to run your app as a FastCGI backend, make sure you're using the FastCGI-enabled version. If this is PHP on Gentoo, add 'fastcgi' to the USE flags. 2012-06-13 18:50:18: (mod_fastcgi.c.1397) [ERROR]: spawning fcgi failed. 

Ich weiß nicht, wohin ich gehen soll. Ich konnte nicht viel darüber finden, wie man den lighttpd-Webserver so einrichten kann, dass er etwas anderes als PHP erzeugt. Wäre das alles mit Apache viel einfacher?

2
Sie müssen das FCGI-Protokoll sprechen, um über einen Unix-Socket zu lighttpd. Ich sehe nicht, wo das hier passiert. Keith vor 11 Jahren 0
Nun, es gibt einen Socket bei `/ var / run / lighttpd / tiny.socket-1`, den meine FCGI-Anwendung erstellt hat. Ich weiß einfach nicht, wie Lighttpd diese Buchse "öffnen" kann. Ich dachte mir, dass es in der Konfigurationsdatei war und etwas mit `cgi-fcgi` zu tun hatte. In mod_fcgi.conf habe ich dasselbe Socket angegeben: `" socket "=>" /var/run/lighttpd/fcgi.socket-1 "` `, aber entweder cgi-fcgi ist das falsche Programm, das aufgerufen werden muss, oder ich rufe es auf falsch. Nick vor 11 Jahren 0
Ich habe die `bin-path`-Zeile in` mod_fastcgi.conf` entfernt, wobei der Socket erhalten bleibt und der Server startet. Der einzige Hinweis, den ich bekomme, dass es diesen Socket in den Protokollen geöffnet hat, ist: "Alle Handler für /tiny.fcgi auf tiny.fcgi sind inaktiv." Jetzt bekomme ich 500/503 Fehler in lighttpd. Nick vor 11 Jahren 0

1 Antwort auf die Frage

1
Nick

Nun, es war das bin-pathSetting, an dem ich aufgehängt wurde. Meine Bewerbung befindet sich jetzt an:

/var/www/localhost/cgi-bin/tiny.fcgi

Der Socket wird erstellt an:

/var/run/lighttpd/tiny.socket-1 (Die '-1' wird von spawn-fcgi erstellt, und es ist chmod'd, so dass lighttpd es r / w kann.)

Die mod_fcgi.confDatei:

server.modules += ("mod_fastcgi")  fastcgi.debug = 1  fastcgi.server = ( ".php" => (( "socket" => "/var/run/lighttpd/lighttpd-fastcgi-php-" + PID + ".socket", "bin-path" => "/usr/bin/php-cgi", )),  "/cgi-bin/" => (( "socket" => "/var/run/lighttpd/tiny.socket-1", # "bin-path" => "/home/nick/zwave/tiny.fcgi", "check-local" => "disable", "max-procs" => 1 )) ) 

Und jetzt funktioniert es!

Also kein bin-Pfad, wenn Sie Ihre eigenen Apps aufrufen, die bereits über einen Socket verfügen. Das Spawn-fcgi startet diese Prozesse, nicht Lighttpd.