http://nginx.org/en/download.html
http://php-fpm.org/
编译安装Linux Nginx
tar zxvf nginx-0.6.35.tar.gz cd nginx-0.6.35/ 默认安装:./configure make && make install 默认情况下,Nginx 会被安装在 /usr/local/nginx。通过设定编译选项,你可以改变这个设定。 指定编译选项安装,如: ./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module make && make install cd ../ 七、Linux Nginx创建fcgi.conf文件 1.rm -f /usr/local/webserver/nginx/conf/fcgi.conf 2.vi /usr/local/webserver/nginx/conf/fcgi.conf 输入以下内容: 1.fastcgi_param GATEWAY_INTERFACE CGI/1.1; 2.fastcgi_param SERVER_SOFTWARE nginx; 3. 4.fastcgi_param QUERY_STRING $query_string; 5.fastcgi_param REQUEST_METHOD $request_method; 6.fastcgi_param CONTENT_TYPE $content_type; 7.fastcgi_param CONTENT_LENGTH $content_length; 8. 9.fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 10.fastcgi_param SCRIPT_NAME $fastcgi_script_name; 11.fastcgi_param REQUEST_URI $request_uri; 12.fastcgi_param DOCUMENT_URI $document_uri; 13.fastcgi_param DOCUMENT_ROOT $document_root; 14.fastcgi_param SERVER_PROTOCOL $server_protocol; 15. 16.fastcgi_param REMOTE_ADDR $remote_addr; 17.fastcgi_param REMOTE_PORT $remote_port; 18.fastcgi_param SERVER_ADDR $server_addr; 19.fastcgi_param SERVER_PORT $server_port; 20.fastcgi_param SERVER_NAME $server_name; 21. 22.# PHP only, required if PHP was built with --enable-force-cgi-redirect 23.fastcgi_param REDIRECT_STATUS 200; 八、编辑Linux Nginx配置文件 1.rm -f /usr/local/webserver/nginx/conf/nginx.conf 2.vi /usr/local/webserver/nginx/conf/nginx.conf 输入以下内容: 1.user www www; 2.worker_processes 8; 3.error_log /usr/local/webserver/nginx/logs/logs/nginx_error.log crit; 4.pid /usr/local/webserver/nginx/logs/nginx.pid; 5.worker_rlimit_nofile 51200; 6.events { 7.use epoll; 8.worker_connections 51200; 9.} 10. 11.http { 12.include mime.types; 13.default_type application/octet-stream; 14.charset utf-8; 15. 16.server_names_hash_bucket_size 128; 17.client_header_buffer_size 32k; 18.large_client_header_buffers 4 32k; 19.client_max_body_size 8m; 20. 21.sendfile on; 22.tcp_nopush on; 23.keepalive_timeout 60; 24.tcp_nodelay on; 25. 26.fastcgi_connect_timeout 300; 27.fastcgi_send_timeout 300; 28.fastcgi_read_timeout 300; 29.fastcgi_buffer_size 64k; 30.fastcgi_buffers 8 64k; 31.fastcgi_busy_buffers_size 128k; 32.fastcgi_temp_file_write_size 128k; 33. 34.gzip on; 35.gzip_min_length 1k; 36.gzip_buffers 4 16k; 37.gzip_http_version 1.0; 38.gzip_comp_level 2; 39.gzip_types text/plain application/x-javascript text/css application/xml; 40.gzip_vary on; 41. 42.#limit_zone crawler $binary_remote_addr 10m; 43.#多个站点设置,站点文件夹必须放在Nginx的html目录,否则不支持多站点 44.server { 45.listen 80; 46.server_name www.v-ec.com; 47.root /usr/local/webserver/nginx/html/www.v-ec.com; 48.index index.php index.html; 49. 50.location ~ .*\.(php|php5)?$ { 51.#fastcgi_pass unix:/tmp/php-cgi.sock; 52.fastcgi_pass 127.0.0.1:9000; 53.fastcgi_index index.php; 54.include fcgi.conf; 55.} 56. 57.location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { 58.expires 30d; 59.} 60. 61.location ~ .*\.(js|css)?$ { 62.expires 6h; 63.} 64. 65.log_format veclog '$remote_addr - $remote_user [$time_local] "$request" ' 66.'$status $body_bytes_sent "$http_referer" ' 67.'"$http_user_agent" $http_x_forwarded_for'; 68.access_log logs/vec.log veclog; 69.} 70.#多个站点设置,站点文件夹必须放在Nginx的html目录,否则不支持多站点 71.server { 72.listen 80; 73.server_name www.w3cgroup.com; 74.root /usr/local/webserver/nginx/html/www.w3cgroup.com; 75.index index.php index.html; 76. 77.location ~ .*\.(php|php5)?$ { 78.#fastcgi_pass unix:/tmp/php-cgi.sock; 79.fastcgi_pass 127.0.0.1:9000; 80.fastcgi_index index.php; 81.include fcgi.conf; 82.} 83. 84.location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { 85.expires 30d; 86.} 87. 88.location ~ .*\.(js|css)?$ { 89.expires 6h; 90.} 91. 92.log_format w3cclog '$remote_addr - $remote_user [$time_local] "$request" ' 93.'$status $body_bytes_sent "$http_referer" ' 94.'"$http_user_agent" $http_x_forwarded_for'; 95.access_log logs/w3c.log w3clog; 96.} 97.} 九、配置开机自动启动Linux Nginx + PHP 1.vi /etc/rc.local 在末尾增加以下内容: 1.ulimit -SHn 51200 2./usr/local/webserver/php/sbin/php-fpm start 3./usr/local/webserver/nginx/sbin/nginx 十、Linux Nginx优化Linux内核参数 1.vi /etc/sysctl.conf 在末尾增加以下内容: 1.net.ipv4.tcp_fin_timeout = 30 2.net.ipv4.tcp_keepalive_time = 300 3.net.ipv4.tcp_syncookies = 1 4.net.ipv4.tcp_tw_reuse = 1 5.net.ipv4.tcp_tw_recycle = 1 使配置立即生效:/sbin/sysctl –p做到这里,可以reboot重启Linux了,不出意外的话应该可以顺利开启Nginx