Nginx in Ubuntu quickly builds the FCGI environment

Source: Internet
Author: User
It is difficult to build the nginx + php environment on FreeBsd. However, due to historical usage problems, there are still many articles about this experience on the internet. with the gradual promotion of Ubuntu, it is necessary to study how to build the nginx + php environment in ubuntu, so that you can easily build the nginx + php environment on FreeBsd, however, due to historical usage issues, there are still many articles on this experience on the internet. with the gradual promotion of Ubuntu, it is necessary to study how to build the nginx + php environment under ubuntu, it is easier for friends who need this and can promote the popularity of Ubuntu. In fact, it is much faster to build an nginx + php environment under Ubuntu than FreeBsd, in FreeBsd, I used ports for installation. compilation is required. in Ubuntu, I installed apt-get install directly. the installation speed is very fast. let's start the installation next!



1. install nginx. execute the following command and it will be completed soon. However, the default installation version of apg-get is 0.5.33.

Sudo apt-get install nginx

Default configuration file installation location:


Conf:/etc/nginx. conf
Bin:/usr/sbin/nginx
Vhost:/etc/nginx/sites-enable/default
Cgi-params:/etc/nginx/fastcgi-params

For example, create a virtual Server



Server {
Listen 80;
Server_name www.yourdomain.com; # Change the domain name as needed
Access_log/var/log/nginx/home. ucenter. access. log; location /{
Root/var/www/yourdomain.com;
Index. php; location ~ . Php $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/var/www/yourdomain.com $ fastcgi_script_name;
Include/etc/nginx/fastcgi_params;
}
}

2. install the php-cgi module.

Execute sudo apt-get install php5-cgi

Default configuration file installation location:


Php-cgi:/usr/bin/php-cgi
Php5-cgi:/usr/bin/php5-cgi
Cgi config:/usr/bin/cgi/php. ini

Modify the cgi. fix_pathinfo data of the php. ini file to 1. the default value is 0 cgi. fix_pathinfo = 1. in this way, the SCRIPT_FILENAME variable can be used normally in php-cgi.

3. installing spawn-fcgi is a lighttpd tool used to control php-cgi.

If the GCC compiling environment is not installed in the system, run the following command to install the build-essential toolkit before installing lighttpd:

Sudo apt-get install build-essential
Wget http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz
Tar-xvf lighttpd-1.4.19.tar.gz
Cd lighttpd-1.4.19/
Sudo apt-get install libpcre3-dev
./Configure-without-zlib-without-bzip2
Make
Sudo cp src/spawn-fcgi/usr/local/bin/spawn-fcgi

The cgi controller is installed.

4. start the test system. start fast_cgi:

Spawn-fcgi-a 127.0.0.1-p 9000-C 5-u www-data-g www-data-f/usr/bin/php-cgi

Note: the ip address and port must correspond to the cgi-pass in the nginx server.-C indicates opening several cgi processes.

Start nginx

Sudo/etc/init. d/nginx start

Well, if there is no error message, it indicates that the configuration is successful. now write a phpinfo test!

Finally, attach the configuration file of my/etc/nginx/sites-enable/default. this configuration file enables the rewrite function.

Server {
Listen 80;
Server_name localhost; access_log/var/log/nginx/localhost. access. log; location /{
Root/var/www/nginx-default;
Index. php; if (-f $ request_filename/index.html ){
Rewrite (. *) $1/index.html break;
}
If (-f $ request_filename/index. php ){
Rewrite (. *) $1/index. php;
}
If (! -F $ request_filename ){
Rewrite (. *)/index. php;
}}

# Error_page 404/404 .html;

# Redirect server error pages to the static page/50x.html
#
Error_page 500 502 503 x.html;
Location =/50x.html {
Root/var/www/nginx-default;
}

# Proxy the PHP scripts to Apache listening on 127.0.0.1: 80
#
# Location ~ . Php $ {
# Proxy_pass http: // 127.0.0.1;
#}

# Pass the PHP scripts to FastCGI server listening on Fig: 9000
#
Location ~ . Php $ {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME/var/www/nginx-default $ fastcgi_script_name;
Include/etc/nginx/fastcgi_params;
}

# Deny access to. htaccess files, if Apache's document root
# Concurs with nginx's one
#
# Location ~ /. Ht {
# Deny all;
#}
}

# Another virtual host using mix of IP-, name-, and port-based configuration
#
# Server {
# Listen 8000;
# Listen somename: 8080;
# Server_name somename alias another. alias;

# Location /{
# Root html;
# Index index.html index.htm;
#}
#}

# HTTPS server
#
# Server {
# Listen 443;
# Server_name localhost;

# Ssl on;
# Ssl_certificate cert. pem;
# Ssl_certificate_key cert. key;

# Ssl_session_timeout 5 m;

# Ssl_protocols SSLv2 SSLv3 TLSv1;
# Ssl_ciphers ALL :! ADH :! EXPORT56: RC4 + RSA: + HIGH: + MEDIUM: + LOW: + SSLv2: + EXP;
# Ssl_prefer_server_ciphers on;

# Location /{
# Root html;
# Index index.html index.htm;
#}
#}


How is it? Is it fast and convenient? try it now. if you are planning to be a WordPress user, you can try it. nginx + php is more efficient than Apache + php!
 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.