Difference between revisions of "Nginx"

From ArchWiki
Jump to: navigation, search
(FastCGI)
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
{{i18n|Nginx}}
 
{{i18n|Nginx}}
  
Nginx (pronounced "engine X") written by Igor Sysoev (Russia) in 2005, is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. According to Netcraft's ''[http://news.netcraft.com/archives/2012/04/04/april-2012-web-server-survey.html April 2012 Web Server Survey]'', Nginx now hosts 10.32% of all domains worldwide, while [[Apache]] hosts about 65.46%. Nginx is now well known for its stability, rich feature set, simple configuration, and low resource consumption.
+
'''Nginx''' (pronounced "engine X") written by Igor Sysoev (Russia) in 2005, is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. According to Netcraft's [http://news.netcraft.com/archives/2012/04/04/april-2012-web-server-survey.html April 2012 Web Server Survey], Nginx now hosts 10.32% of all domains worldwide, while [[Apache]] hosts about 65.46%. Nginx is now well known for its stability, rich feature set, simple configuration, and low resource consumption.
  
 
== Installation ==
 
== Installation ==
  
The {{Pkg|nginx}} package is now in the [[Official Repositories|official repositories]].
+
The {{Pkg|nginx}} package is in the [[Official Repositories|official repositories]].
 +
# pacman -Sy nginx
  
For Ruby on Rails oriented installation, see [[RubyOnRails#Option_C:_The_Perfect_Rails_Setup|The Perfect Rails Setup]].
+
{{note|For a '''Ruby on Rails''' oriented installation, see [[RubyOnRails#Option_C:_The_Perfect_Rails_Setup|The Perfect Rails Setup]].}}
  
 
== Starting Service ==
 
== Starting Service ==
Line 15: Line 16:
 
  # rc.d start nginx
 
  # rc.d start nginx
  
The default served (i.e. the page served at http://127.0.0.1) page is:  
+
The default served page at http://127.0.0.1 is:  
  /etc/nginx/html/index.html
+
  /srv/http/index.html
  
(The {{Pkg|nginx}} package does not install a default {{ic|index.html}} file; you must create this file yourself, if you wish).
+
The {{Pkg|nginx}} package does not install a default {{ic|index.html}} file; you must create this file yourself, if you wish.
 
+
After creating a {{ic|/etc/nginx/html/index.html}} webpage, you can use this URL: <nowiki>http://127.0.0.1</nowiki> to test if Nginx is working.
+
  
 
To enable the Nginx service by default at start-up just add {{Ic|nginx}} to the {{Ic|DAEMONS}} array in {{ic|/etc/rc.conf}}:
 
To enable the Nginx service by default at start-up just add {{Ic|nginx}} to the {{Ic|DAEMONS}} array in {{ic|/etc/rc.conf}}:
Line 27: Line 26:
 
== Configuring ==
 
== Configuring ==
  
You can modify the configurations by editing the files in {{ic|/etc/nginx/conf}}. ({{ic|/etc/nginx/conf/nginx.conf}} being the main config file.)
+
You can modify the configurations by editing the files in {{ic|/etc/nginx/conf}}, being ({{ic|/etc/nginx/conf/nginx.conf}} the main config file.  
  
More details can be found here: [http://wiki.codemongers.com/NginxConfiguration Nginx Configuration Examples].
+
More details can be found here: [http://wiki.nginx.org/NginxConfiguration Nginx Configuration Examples].
  
=== PHP/Python Integration ===
+
=== FastCGI ===
  
FastCGI technology is introduced into Nginx to work with many external tools and servers, i.e.: [[PHP]] and [[Python]]. So, you cannot use PHP or Python service unless FastCGI server has been started.  
+
FastCGI, also FCGI, is a protocol for interfacing interactive programs with a web server. FastCGI is a variation on the earlier Common Gateway Interface (CGI); FastCGI's main aim is to reduce the overhead associated with interfacing the web server and CGI programs, allowing a server to handle more web page requests at once.
  
PHP and Python can be run as FastCGI application and can process FastCGI requests from Nginx.
+
FastCGI technology is introduced into Nginx to work with many external tools, i.e.: [[Perl]], [[PHP]] and [[Python]]. So, you cannot use these unless a FastCGI server has been started.  
  
FastCGI is usually faster than implementations in e.g. Apache where PHP is loaded each time, with FastCGI the script is simply passed to the PHP daemon, and the appropriate value is returned and used by Nginx.
+
==== PHP implementation ====
  
==== Step 1: Start the FastCGI server ====
+
There are different ways to run a FastCGI server for PHP.
  
There are two different ways to run FastCGI server. It is recommended to use a [[NginX#2nd_Method_.28third_party_wrapper.29|third party wrapper]] (the second method).
+
===== Step 1: PHP configuration =====
  
===== 1st Method "New" (as of PHP 5.3.3) =====
+
The {{Ic|open_basedir}} in {{ic|/etc/php/php.ini}} has to list base directories which contain PHP files, like {{ic|/srv/http/}} and {{ic|/usr/share/webapps/}}:
 +
open_basedir = /usr/share/webapps/:/srv/http/:/home/:/tmp/:/usr/share/pear/
  
PHP now contains a FastCGI server spawner that takes care of everything for you.
+
===== Step 2, option A: php-fpm =====
  
To get started, install {{Pkg|php-fpm}} and then start the service:
+
* http://php-fpm.org
# rc.d start php-fpm
+
  
Now, move to: [https://wiki.archlinux.org/index.php/Nginx#Step_2:_Edit_.2Fetc.2Fnginx.2Fconf.2Fnginx.conf Step 2].
+
Install {{Pkg|php-fpm}}:
{{Note|You can configure the number of servers in the pool and tweak other configuration options by editing the file {{ic|/etc/php/php-fpm.conf}}. More details on ''php-fpm'' can be found on the [http://php-fpm.anight.org/ php-fpm website].}}
+
# pacman -Sy php-fpm
  
===== 1st Method "Old" (PHP's built-in) =====
+
The configuration file is {{ic|/etc/php/php-fpm.conf}}.
  
Directly running PHP's built-in FastCGI server -- this method does not require any third party tools.
+
To start the service:
 +
# rc.d start php-fpm
  
Arch Linux's {{Pkg|php}} package in the [[Official Repositories|official repositories]] has FastCGI support enabled already.
+
Add {{Ic|php-fpm}} to the {{Ic|DAEMONS}} array in {{ic|/etc/rc.conf}}.
  
For example, install {{Pkg|php}} and {{Pkg|php-cgi}}, and then run:
+
===== Step 2, option B: spawn-fcgi-php =====
$ php-cgi -b 127.0.0.1:9000 &
+
  
This command sets up the local machine as a FastCGI server using port 9000.
+
Install {{Aur|spawn-fcgi-php}}, available at [[AUR]]:
 +
$ yaourt -Sy spawn-fcgi-php
  
{{Note|Since NginX 0.7.62, the default internal {{Ic|$document_root}} is {{ic|/etc/nginx/html}} which is moved outside the default NginX directory and symlinked to {{ic|/usr/share/nginx/http}} in the Arch Linux package. For PHP to work with NginX 0.7.62 the open_basedir in {{ic|/etc/php/php.ini}} has to contain the directory {{ic|/etc/nginx/html}}:<br>
+
The configuration file is {{ic|/etc/conf.d/spawn-fcgi-php.conf}}.
{{ic|open_basedir <nowiki>=</nowiki> /etc/nginx/html/:/srv/http/:/home/:/tmp/:/usr/share/pear/}}.}}
+
  
Below is a daemon script to be used in {{ic|/etc/rc.conf}} to start PHP-cgi on boot. Save it as {{ic|/etc/rc.d/fastcgi}} and add {{Ic|fastcgi}} to your {{Ic|DAEMONS}} array in {{ic|/etc/rc.conf}}
+
To start the service:
 +
# rc.d start spawn-fcgi-php
  
  #!/bin/bash
+
Add {{Ic|spawn-fcgi-php}} to the {{Ic|DAEMONS}} array in {{ic|/etc/rc.conf}}.
 
+
  . /etc/rc.conf
+
  . /etc/rc.d/functions
+
 
+
  case "$1" in
+
    start)
+
  stat_busy 'Starting Fastcgi Server'
+
  if /usr/bin/php-cgi -b 127.0.0.1:9000 &
+
  then
+
  add_daemon fastcgi
+
  stat_done
+
  else
+
  stat_fail fi
+
  fi
+
  ;;
+
    stop)
+
  stat_busy 'Stopping Fastcgi Server'
+
  [ -e /var/run/daemons/fastcgi ] && kill $(pidof php-cgi) &> /dev/null;
+
  if [ $? -gt 0 ]; then
+
  stat_fail
+
  else
+
  rm_daemon fastcgi
+
  stat_done
+
  fi
+
  ;;
+
    restart)
+
  $0 stop
+
  $0 start
+
  ;;
+
    *)
+
  echo "Usage: $0 {start|stop|restart}"
+
  esac
+
  
===== 2nd Method (third party wrapper) =====
+
===== Step 3: Nginx configuration =====
  
This can be more comfortable than the first method because of increased flexibility.
+
Inside each {{Ic|server}} block serving a PHP web application should appear a {{Ic|location}} block similar to:
 
+
There are currently three options for deploying [[PHP]] on Nginx:
+
 
+
* ''fcgi''
+
** Includes ''cgi-fcgi''
+
* ''lighttpd''
+
** Includes ''spawn-fcgi''
+
* '''''PHP-FPM''''' (Recommended: see above)
+
 
+
To spawn a process, issue one of the following commands (matching the package you installed):
+
 
+
# cgi-fcgi -start -connect localhost:9000 /usr/bin/php-cgi
+
 
+
# spawn-fcgi -a 127.0.0.1 -p 9000 -C 9 -f /usr/bin/php-cgi
+
 
+
# php --fpm -b 127.0.0.1:
+
 
+
{{Note|You may need to edit {{ic|/etc/php/php-fpm.conf}} at first. More details on ''php-fpm'' can be found at the [http://php-fpm.anight.org/ php-fpm website].}}
+
 
+
{{Note|Sometimes, you may encounter some permission issue when running some third party software to start PHP as FastCGI-server. See [[Nginx#Troubleshooting]].}}
+
 
+
==== Step 2: Edit /etc/nginx/conf/nginx.conf ====
+
 
+
Add index.php after index.htm in this line: ''(example below has index.php already added, you need to add it to your file manually)''
+
location / {
+
      root    html;
+
      index  index.html index.htm index.php;
+
}
+
 
+
Then uncomment these lines and edit in the file to be as follows:
+
 
   location ~ \.php$ {
 
   location ~ \.php$ {
      try_files $uri =404;
 
      root          html;
 
 
       fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
 
       fastcgi_pass  unix:/var/run/php-fpm/php-fpm.sock;
 
       fastcgi_index  index.php;  
 
       fastcgi_index  index.php;  
      fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
+
       include        fastcgi.conf;
       include        fastcgi_params;
+
 
   }
 
   }
 +
'''Pay attention''' to the {{Ic|fastcgi_pass}} argument, as it must be the TCP or Unix socket defined by the chosen FastCGI server in its config file. The '''default''' Unix for {{Ic|php-fpm}} is
 +
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
 +
and for {{Ic|spawn-fcgi-php}},
 +
fastcgi_pass unix:/var/run/spawn-fcgi-php.sock;
 +
. Or you may use the common TCP socket, '''not default''',
 +
fastcgi_pass 127.0.0.1:9000;
 +
. Unix domain sockets are however much better.
  
{{Note|If you are not using {{Pkg|php-fpm}}, you may want to change the '''fastcgi_pass''' value to '''127.0.0.1:9000''', or whichever IP and port to which your server is configured to respond. Do not forget the semicolon at the end of the line.}}
+
{{Ic|fastcgi.conf}} or {{Ic|fastcgi_params}} are usually included because they hold FastCGI settings for Nginx; the use of the latter is deprecated, though. They come within the Nginx installation.
  
{{Note|If you are planning to run applications that support file uploads (images, for example), be sure and include the {{Ic|try_files}} line in the above configuration, otherwise you may be exposed to a security risk by allowing arbitrary code execution. The short explanation for this behavior is that a properly crafted URI which ends in ".php", in combination with a malicious image file that actually contains valid PHP, can result in the image being processed as PHP. For more information on the specifics of this behavior, you may wish to review the information provided on [https://nealpoole.com/blog/2011/04/setting-up-php-fastcgi-and-nginx-dont-trust-the-tutorials-check-your-configuration/ Neal Poole's blog]. If you are running FastCGI on another machine, this won't work and you should look at a better way to solve this.}}
+
Finally, if Nginx has been working, run:
 
+
==== Step 3: Restart Nginx ====
+
 
+
If Nginx has been working, run:
+
 
  # rc.d restart nginx
 
  # rc.d restart nginx
  
Edit {{ic|/srv/http/nginx/index.php}},
+
If you would like to test the FastCGI implementation, create {{ic|/srv/http/index.php}} with content
 
  <?php
 
  <?php
 
   phpinfo();
 
   phpinfo();
 
  ?>  
 
  ?>  
Visit the URL: <nowiki>http://localhost/index.php</nowiki> with your browser, and you will find PHP has worked well with Nginx.
+
and visit the URL http://127.0.0.1/index.php with your browser.
 
+
=== Ruby Integration (Ruby on Rails and Rack-based) ===
+
 
+
The [http://wiki.rubyonrails.org/ Ruby on Rails wiki] has tutorials on configuring Ruby for [http://nginx.org/ Nginx]. It is not recommended to use [http://www.fastcgi.com/drupal/ FastCGI] to make Nginx work with Ruby anymore, although very well possible.
+
[http://nginx.org/ Nginx] and [http://modrails.com/ Passenger] are a great toolkit, and this setup is extremely easy to achieve on Archlinux.
+
It should be noted, however, that there are other alternatives, including [http://github.com/fauna/mongrel Mongrel], [http://code.macournoyer.com/thin/ Thin] and [http://unicorn.bogomips.org/ Unicorn].
+
 
+
==== Setting up Nginx and Passenger ====
+
 
+
Install the Nginx Passenger package from the [[AUR]], and you are ready to go.
+
 
+
For further information on setting up Nginx with Ruby, read the Nginx part of [http://wiki.rubyonrails.org/deployment/vps-setup-nginx-passenger this tutorial].
+
  
{{Note|With Passenger you are also able to run other Rack-based applications, including Sinatra. Note, however, that these require a {{ic|config.ru}} file in the source directory.}}
+
==== CGI implementation ====
  
=== phpMyAdmin Setup ===
+
This implementation is needed for CGI applications.
  
See the following wiki article: [[PhpMyAdmin#NGINX_Configuration]].
+
===== fcgiwrap =====
  
=== Security ===
+
Install {{Pkg|fcgiwrap}}:
 +
# pacman -Sy fcgiwrap
 +
. The default configuration sets TCP socket 127.0.0.1:9001 for listening. If you desire to use a Unix domain socket, edit {{ic|/etc/conf.d/fcgiwrap}} like this:
 +
SPAWNER='/usr/bin/spawn-fcgi'
 +
 +
FCGI_SOCKET='/var/run/fcgiwrap.sock'
 +
FCGI_USER='http'
 +
FCGI_GROUP='http'
 +
FCGI_EXTRA_OPTIONS='-M 700'
 +
 +
SPAWNER_ARGS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET $FCGI_EXTRA_OPTIONS -- /usr/sbin/fcgiwrap"
 +
. Start the service:
 +
# rc.d start fcgiwrap
 +
, and add {{Ic|fcgiwrap}} to the {{Ic|DAEMONS}} array in {{ic|/etc/rc.conf}}.
  
* Allow/deny visitors based on IP:
+
Respectively, Nginx will need
[http://wiki.codemongers.com/NginxHttpAccessModule ngx_http_access_module].
+
fastcgi_pass 127.0.0.1:9001;
* HTTP authentication:
+
or
[http://wiki.codemongers.com/NginxHttpAuthBasicModule ngx_http_auth_basic_module].
+
fastcgi_pass unix:/var/run/fcgiwrap.sock;
* HTTPS support:
+
directives.
[http://wiki.codemongers.com/NginxHttpSslModule ngx_http_ssl_module].
+
  
 
== Troubleshooting ==
 
== Troubleshooting ==
Line 206: Line 144:
 
=== Error: 404 (Pathinfo error) ===
 
=== Error: 404 (Pathinfo error) ===
  
In some framework(like thinkphp, cakephp) or CMS, they need the pathinfo function.  
+
In some framework (like thinkphp, cakephp) or CMS, they need the pathinfo function.  
  
 
1. Edit the file {{ic|/etc/php/php.ini}}, make sure
 
1. Edit the file {{ic|/etc/php/php.ini}}, make sure
Line 264: Line 202:
 
== See Also ==
 
== See Also ==
 
* [[Nginx/Init_script|Init script for Nginx]]
 
* [[Nginx/Init_script|Init script for Nginx]]
* [http://nginx.net/ Nginx Official Site]
+
* [http://nginx.org/ Nginx Official Site]
* [http://wiki.nginx.org/Main Nginx Wiki]
+
 
* [http://calomel.org/nginx.html Nginx HowTo]
 
* [http://calomel.org/nginx.html Nginx HowTo]
 
* [http://wiki.gotux.net/config:nginx Easy Config Files]
 
* [http://wiki.gotux.net/config:nginx Easy Config Files]

Revision as of 06:11, 19 May 2012

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Nginx (pronounced "engine X") written by Igor Sysoev (Russia) in 2005, is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. According to Netcraft's April 2012 Web Server Survey, Nginx now hosts 10.32% of all domains worldwide, while Apache hosts about 65.46%. Nginx is now well known for its stability, rich feature set, simple configuration, and low resource consumption.

Installation

The nginx package is in the official repositories.

# pacman -Sy nginx
Note: For a Ruby on Rails oriented installation, see The Perfect Rails Setup.

Starting Service

To start the Nginx service, run:

# rc.d start nginx

The default served page at http://127.0.0.1 is:

/srv/http/index.html

The nginx package does not install a default index.html file; you must create this file yourself, if you wish.

To enable the Nginx service by default at start-up just add nginx to the DAEMONS array in /etc/rc.conf:

DAEMONS=(ntpd syslog-ng ... nginx)

Configuring

You can modify the configurations by editing the files in /etc/nginx/conf, being (/etc/nginx/conf/nginx.conf the main config file.

More details can be found here: Nginx Configuration Examples.

FastCGI

FastCGI, also FCGI, is a protocol for interfacing interactive programs with a web server. FastCGI is a variation on the earlier Common Gateway Interface (CGI); FastCGI's main aim is to reduce the overhead associated with interfacing the web server and CGI programs, allowing a server to handle more web page requests at once.

FastCGI technology is introduced into Nginx to work with many external tools, i.e.: Perl, PHP and Python. So, you cannot use these unless a FastCGI server has been started.

PHP implementation

There are different ways to run a FastCGI server for PHP.

Step 1: PHP configuration

The open_basedir in /etc/php/php.ini has to list base directories which contain PHP files, like /srv/http/ and /usr/share/webapps/:

open_basedir = /usr/share/webapps/:/srv/http/:/home/:/tmp/:/usr/share/pear/
Step 2, option A: php-fpm

Install php-fpm:

# pacman -Sy php-fpm

The configuration file is /etc/php/php-fpm.conf.

To start the service:

# rc.d start php-fpm

Add php-fpm to the DAEMONS array in /etc/rc.conf.

Step 2, option B: spawn-fcgi-php

Install spawn-fcgi-phpAUR, available at AUR:

$ yaourt -Sy spawn-fcgi-php

The configuration file is /etc/conf.d/spawn-fcgi-php.conf.

To start the service:

# rc.d start spawn-fcgi-php

Add spawn-fcgi-php to the DAEMONS array in /etc/rc.conf.

Step 3: Nginx configuration

Inside each server block serving a PHP web application should appear a location block similar to:

 location ~ \.php$ {
      fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;
      fastcgi_index  index.php; 
      include        fastcgi.conf;
 }

Pay attention to the fastcgi_pass argument, as it must be the TCP or Unix socket defined by the chosen FastCGI server in its config file. The default Unix for php-fpm is

fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;

and for spawn-fcgi-php,

fastcgi_pass unix:/var/run/spawn-fcgi-php.sock;

. Or you may use the common TCP socket, not default,

fastcgi_pass 127.0.0.1:9000;

. Unix domain sockets are however much better.

fastcgi.conf or fastcgi_params are usually included because they hold FastCGI settings for Nginx; the use of the latter is deprecated, though. They come within the Nginx installation.

Finally, if Nginx has been working, run:

# rc.d restart nginx

If you would like to test the FastCGI implementation, create /srv/http/index.php with content

<?php
  phpinfo();
?> 

and visit the URL http://127.0.0.1/index.php with your browser.

CGI implementation

This implementation is needed for CGI applications.

fcgiwrap

Install fcgiwrap:

# pacman -Sy fcgiwrap

. The default configuration sets TCP socket 127.0.0.1:9001 for listening. If you desire to use a Unix domain socket, edit /etc/conf.d/fcgiwrap like this:

SPAWNER='/usr/bin/spawn-fcgi'

FCGI_SOCKET='/var/run/fcgiwrap.sock'
FCGI_USER='http'
FCGI_GROUP='http'
FCGI_EXTRA_OPTIONS='-M 700'

SPAWNER_ARGS="-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET $FCGI_EXTRA_OPTIONS -- /usr/sbin/fcgiwrap"

. Start the service:

# rc.d start fcgiwrap

, and add fcgiwrap to the DAEMONS array in /etc/rc.conf.

Respectively, Nginx will need

fastcgi_pass 127.0.0.1:9001;

or

fastcgi_pass unix:/var/run/fcgiwrap.sock;

directives.

Troubleshooting

Accessing local IP redirects to localhost

Solution from the Arch Linux forum.

Edit /etc/nginx/nginx.conf and locate the "server_name localhost" line without a # infront of it, and add below:

server_name_in_redirect off;

Default behavior is that nginx redirects any requests to the value given as server_name in the config.

Error: 403 (Permission error)

This is most likely a permission error. Are you sure whatever user configured in the Nginx configuration is able to read the correct files?

If the files are located within a home directory, (e.g. /home/arch/public/webapp) and you are sure the user running Nginx has the right permissions (you can temporarily chmod all the files to 777 in order to determine this), /home/arch might be chmod 750, simply chmod it to 751, and it should work.

Error: 404 (Pathinfo error)

In some framework (like thinkphp, cakephp) or CMS, they need the pathinfo function.

1. Edit the file /etc/php/php.ini, make sure

cgi.fix_pathinfo=1

2. Edit /etc/nginx/conf/nginx.conf, comment

location ~ \.php$ {
...
}

to

#location ~ \.php$ {
#...
#}

Then add the follows,

location ~ ^(.+\.php)(.*)$ {
  root   /srv/http/nginx;
  fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock; 	
  #fastcgi_pass   127.0.0.1:9000; #Un-comment this and comment "fastcgi_pass   unix:/var/run/php-fpm/php-fpm.sock;" if you are not using php-fpm.
  fastcgi_index  index.php;
  set $document_root2 $document_root;
  if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") { set $document_root2 $1$2; }
  if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") {	set $document_root2 $1$2; }
  if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") {	set $document_root2 $1$2; }
  if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") {	set $document_root2 $1$2; }
  if ($document_root2 ~ "^(.*\\\\).*?[\\\\|\/]\.\.\/(.*)$") {	set $document_root2 $1$2; }
  fastcgi_split_path_info ^(.+\.php)(.*)$;
  fastcgi_param	SCRIPT_FILENAME	$document_root2$fastcgi_script_name;
  fastcgi_param	PATH_INFO	$fastcgi_path_info;
  fastcgi_param	PATH_TRANSLATED	$document_root2$fastcgi_path_info;
  include	fastcgi_params;
  fastcgi_param  DOCUMENT_ROOT      $document_root2;
}

Error: The page you are looking for is temporarily unavailable. Please try again later.

This is because the FastCGI server has not been started.

Error: No input file specified

Most Likely you do not have the SCRIPT_FILENAME containing the full path to you scripts. If the configuration of nginx (fastcgi_param SCRIPT_FILENAME) is all right, this kind of error means php fail to load the requestd script. Usually it is simply a permissions issue, you can just run php-cgi as root

# spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/php-cgi

or you should create some group and user to start the php-cgi. For example:

# groupadd www
# useradd -g www www
# chmod +w /srv/www/nginx/html
# chown -R www:www /srv/www/nginx/html
# spawn-fcgi -a 127.0.0.1 -p 9000 -u www -g www -f /usr/bin/php-cgi

Another occasion is that, wrong "root" argument in the "location ~ \.php$" section in nginx.conf, make sure the "root" points to the same directory as it in "location /" in the same server. Or you may just set root as global, do not define it in any location section.

Also keep in mind that your php script path was defined as /srv/www/nginx/html by default using the variable "open_basedir" in /etc/php/php.ini; you can change them if you need.

See Also