How To Automatically Start Nginx & Fastcgi on Reboot on Fedora LinuxBy Angsuman Chakraborty, Gaea News Network
Sunday, August 10, 2008
nginx [engine x] is a high quality, light footprint (much ligher than Apache HTTPD), high performance HTTP server and mail proxy server written by Igor Sysoev. nginx is distributed under BSD license unlike its competitor Lighttpd. We are progressively transferring our sites over to nginx. Today when I had to restart the server, I realized (after few hours) with horror that we had forgot to add the script to start nginx automatically after reboot. When you want any command to execute everytime after a reboot you should add it to /etc/rc.local. The commands in rc.local are executed *after* all the other init scripts. To automatically start nginx as well as fastcgi on reboot you should add the following lines to /etc/rc.local at the end -
/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -f /usr/bin/php-cgi -P /var/run/fastcgi-php.pid
- Change the port number as appropriate.
- The IP address may be changed if fastcgi is started on a different machine than from which it is accessed by nginx
- First verify the commands by executing them from console
- If nginx or spawn-fcgi is not available in the (default) location above then you can locate it with locate command like this:
- You should test your rc.local by actually rebooting the system and ensuring that fastcgi & nginx are actually started.
Another way to start nginx would be through service. However for that you will first need to create the init script in /etc/rc.d/init.d. Check out files like /etc/rc.d/init.d/network as an example.
Note: In Fedora Linux nginx init script (allowing you start, stop and restart using service and also auto-start on startup) is installed if you use the binary distribution.
Tags: Apache HTTPD, HTTP Server, nginx, Web Server