REHL 5.4 下編譯安裝LNMP(下)

12. 安裝 Nginx的rewrite模塊支持包pcre庫
tar zxvf pcre-8.10.tar.gz
cd pcre-8.10/
./configure
make && make install
cd ../
13. 安裝 Nginx
tar zxvf nginx-0.8.46.tar.gz
cd nginx-0.8.46/
./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
cd ../
14.nginx配置
1.在/usr/local/nginx/conf/目錄中建立nginx.conf文件:原配置文件只是基本配置文件,要實現其它功能還須要在此基礎上進行修改。
cd /usr/local/nginx/conf/
cp nginx.conf nginx.conf.bk
vi nginx.conf  能夠將註釋刪掉
user  nginx nginx;        /*啓動nginx服務的用戶與組*/
worker_processes 1;   /*啓動nginx服務的工做進程*/
error_log  logs/nginx_error.log  crit; /*錯誤日誌,以及等級*/
pid        /usr/local/nginx/nginx.pid;  /*nginx服務進程PID*/
worker_rlimit_nofile 51200; 
events
{
 use epoll;                /*工做模式*/
 worker_connections 51200; /*每進程容許最大的同時鏈接數*/
}
http
{
 include       mime.types;
 default_type  application/octet-stream;
 #charset  gb2312;
 server_names_hash_bucket_size 128;
 client_header_buffer_size 32k;
 large_client_header_buffers 4 32k;
 sendfile on;
 tcp_nopush     on;
 keepalive_timeout 60;
 tcp_nodelay on;
 fastcgi_connect_timeout 300;
 fastcgi_send_timeout 300;
 fastcgi_read_timeout 300;
 fastcgi_buffer_size 64k;
 fastcgi_buffers 4 64k;
 fastcgi_busy_buffers_size 128k;
 fastcgi_temp_file_write_size 128k;
 gzip on;
 gzip_min_length  1k;
 gzip_buffers     4 16k;
 gzip_http_version 1.0;
 gzip_comp_level 2;
 gzip_types text/plain application/x-javascript text/css application/xml;
 gzip_vary on;
 #limit_zone  crawler  $binary_remote_addr  10m;
 server
 {
   listen       80;               /*監聽端口*/
   server_name  localhost;        /*服務器名稱*/
   index index.php index.html index.htm;  /*缺省主頁名稱*/
   root  /usr/local/nginx/html;   /*網站根目錄,也能夠採用下面內容,相對路徑*/
   #location / {
   #         root   html;
   #         index  index.html index.htm;
   # }
   #limit_conn   crawler  20;   
   #經過FastCGI方式支持PHP,php頁面由fastcgi代理處理,這也是反向代理的一個應用,這裏能夠是jsp/asp等腳本。
   #Nginx是經過本機的9000端口將PHP請求轉發給PHP的,PHP本身是從本機的9000端口偵聽數據,Nginx與PHP經過本機的9000端口完成了數據請求。
   location ~ .*\.(php|php5)?$
   {     
     #fastcgi_pass  unix:/tmp/php-cgi.sock;
     fastcgi_pass  127.0.0.1:9000;   /*fastcgi監聽端口*/
     fastcgi_index index.php;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include        fastcgi_params;
     include fcgi.conf;       /*fastcgi配置文件,修改成如下內容*/
   }
   #對於某一類型的文件,設置過時時間,靜態的頁面一般設置長一點。
   #靜態文件,nginx本身處理
   location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
   {
     expires      30d;
   }
#日誌的格式
   log_format  access  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
             '"$http_user_agent" $http_x_forwarded_for';
   access_log  logs/access.log  access;
     }
}
2.在/usr/local/nginx/conf/目錄中建立fcgi.conf文件:
說明:能夠直接粘貼如下內容。
vi /usr/local/nginx/conf/fcgi.conf
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;
1五、nginx啓動與管理
1.啓動nginx
/usr/local/nginx/sbin/nginx
2.測試nginx配置文件
修改/usr/local/nginx/conf/nginx.conf配置文件後,請執行如下命令檢查配置文件是否正確:
# /usr/local/nginx/sbin/nginx -t
若是屏幕顯示如下兩行信息,說明配置文件正確:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
the configuration file /usr/local/nginx/conf/nginx.conf was tested successfully
3.查看Nginx主進程號
ps -ef | grep "nginx: master process" | grep -v "grep" | awk -F ' ' '{print $2}'
屏幕顯示的即爲Nginx主進程號,例如:
6302
這時,執行如下命令便可使修改過的Nginx配置文件生效:
kill -HUP 6302
或者無需這麼麻煩,找到Nginx的Pid文件:
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
4.配置開機自動啓動Nginx + PHP
vi /etc/rc.local
加入如下內容:
ulimit -SHn 51200
/usr/local/php/sbin/php-fpm start
/usr/local/nginx/sbin/nginx
5.測試nginx
vi /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
http://YOUR SERVERIP
 javascript

相關文章
相關標籤/搜索