Home | Mirror | Search

第 24 章 Nginx

目錄

1. install nginx
1.1. spawn-fcgi script
1.2. php-fpm
1.3. fastcgi backend
2. worker_processes
3. events
4. http 配置
4.1. X-Forwarded-For
4.2. server
4.2.1. VirtualHost (虛擬主機)
4.2.2. location
4.2.3. ssl
4.3. expires
4.4. access
4.5. auth_basic
4.6. autoindex
4.7. ssi
4.8. rewrite
4.9. gzip
4.10. Cache
4.11. stub_status
4.12. server_tokens
4.13. add_header
4.13.1. Access-Control-Allow
4.14. valid_referers
5. Proxy
5.1. request_filename + proxy_pass
5.2. proxy_cache
5.3. proxy_cache
5.4. expires
5.5. X-Sendfile
5.6. FAQ
yum install nginx
yum -y install mysql mysql-server
yum -y install php php-cgi php-mysql php-mbstring php-gd php-fastcgi
yum -y install perl-DBI perl-DBD-MySQL
	

1. install nginx

1.1. spawn-fcgi script

yum -y install spawn-fcgi
			

/etc/sysconfig/spawn-fcgi

移除SOCKET與OPTIONS註釋, apache改為nginx

# cat /etc/sysconfig/spawn-fcgi
# You must set some working options before the "spawn-fcgi" service will work.
# If SOCKET points to a file, then this file is cleaned up by the init script.
#
# See spawn-fcgi(1) for all possible options.
#
# Example :
SOCKET=/var/run/php-fcgi.sock
OPTIONS="-u apache -g apache -s $SOCKET -S -M 0600 -C 32 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi"
			
			
chkconfig spawn-fcgi on
			
			

starting spawn-fcgi

/etc/init.d/spawn-fcgi start
			

check port

# netstat -nl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN
tcp        0      0 :::22                       :::*                        LISTEN
Active UNIX domain sockets (only servers)
Proto RefCnt Flags       Type       State         I-Node Path
unix  2      [ ACC ]     STREAM     LISTENING     25282  /var/run/php-fcgi.sock
unix  2      [ ACC ]     STREAM     LISTENING     8227   @/com/ubuntu/upstart
			
			

Unix domain socket

location ~ \.php$ { fastcgi_pass unix:/var/run/php-fcgi.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name; include fastcgi_params; }

TCP/IP

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -g nginx -d /www -C 32 -F 1 -P /var/run/spawn-fcgi.pid -f /usr/bin/php-cgi
			

			
        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        fastcgi_params;
        }
			
			
# netstat -tulpn | grep :9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      26877/php-cgi
			
chkconfig nginx on
			

check config

nginx -t
			

1.2. php-fpm

rpm -Uvh http://download.fedora.redhat.com/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
yum install nginx -y
			

chkconfig nginx on
			

check config

nginx -t
			

其他 php-fpm YUM源

rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
			
# rpm -Uvh http://centos.alt.ru/repository/centos/6/i386/centalt-release-6-1.noarch.rpm
# yum update
			

1.3. fastcgi backend

			
upstream backend  {
  server   localhost:1234;
}

fastcgi_pass   backend;
			
			
comments powered by Disqus