大鳥的學習樂園
          路漫漫其修遠兮,吾將上下而求索
          posts - 26,comments - 27,trackbacks - 0

          h1. Nginx編譯,安裝配置

           

          * Nginx?

          Apache知道吧,Nginx和他一也是webserver,不他比Apache快,據快很多很多,尤其是在高荷的候。

          BTW,玩意是某俄國大牛一個人寫的......

           

          * 編譯

          ./configure --prefix=/usr/local/nginx

          make && make install

           

          * 配置虛主機

          /usr/local/nginx/conf/nginx.conf 內容如下

          <pre>

          user www;

          worker_processes  1;

          events {

              worker_connections  1024;

          }

           

          http {

              include       mime.types;

              default_type  application/octet-stream;

              sendfile        on;

              #tcp_nopush     on;

           

              #keepalive_timeout  0;

              keepalive_timeout  65;

           

              #gzip  on;

           

              # [Add by lemon] Include vhost config

              include /usr/local/nginx/conf/vhost/www_site1_com.conf;

              include /usr/local/nginx/conf/vhost/www_site2_com.conf;

          </pre>

          /usr/local/nginx/conf/vhost/www_site1_com.conf 內容如下

          <pre>

          server {

              listen 192.168.188.132:80;

              client_max_body_size 100M;

              server_name  www.site1.com;

              #charset gb2312;

              index index.html index.htm index.php;

              root   /home/www/site1;         #你的站點路徑

           

              #錄瀏覽,這樣當沒有找到index文件,就也已瀏覽中的文件

           

              autoindex  on;

           

              if (-d $request_filename) {

              rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;

              }

           

              error_page  404              /404.html;

              location = /40x.html {

              root  /home/www/site1;       #你的站點路徑

              charset    on;

              }

           

              # redirect server error pages to the  static page /50x.html

           

              #

           

              error_page   500 502 503 504  /50x.html;

           

              location = /50x.html {

              root   /home/www/site1;      #你的站點路徑

              charset    on;

              }

           

              #將客端的fastcgi

           

              location ~ .*\.(php|php5|php4|shtml|xhtml|phtml)?$ {

           

              fastcgi_pass   127.0.0.1:9000;

           

              include /usr/local/nginx/conf/fastcgi_params;

           

              }

           

              #網站的多,更改少,將它瀏覽器本地15

           

              location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

           

              {

           

              expires      15d;

           

              }

           

              #網站會加很多JSCSS,將它瀏覽器本地1

           

              location ~ .*\.(js|css)?$

              {

              expires      1d;

              }

           

              location /(WEB-INF)/ {

              deny all;

              }

           

              #定日志格式

           

              log_format  site1_access  '$remote_addr - $remote_user [$time_local] "$request" '

           

              '$status $body_bytes_sent "$http_referer" '

           

              ' "$http_user_agent" $http_x_forwarded_for';

           

              #定本虛主機的訪問日志

           

              access_log  /home/www/site1/logs/nginx/access.log  site1_access;   #日志的路徑,個虛機一個,不能相同

           

              #防止nginxweb,server_name問題.擊這看原文

              server_name_in_redirect  off;

          }

          </pre>

          /usr/local/nginx/conf/vhost/www_site2_com.conf www_site1_com.conf 基本一,只需把site1site2即可。

           

          * Nginx+PHP

          Nginx 只是一個http器,本身不能php但它可以通fastcgi調php

          php內置了一個fastcgi server, 需要通php-fpm來啟,個在編譯php需要指定參數,以cgi模式編譯

          所以,Nginx只要配置把php求交fastcgi server的部分即可,剩下的事情交 fastcig server去做。

          <pre>

          location ~ \.php$ {

                      root           html;

                      fastcgi_pass   127.0.0.1:9000;

                      fastcgi_index  index.php;

                      fastcgi_param SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;

                      include        fastcgi_params;

                  }

          </pre>

          /usr/local/nginx/html/NginxDocumentRoot

           

          * 主機與IP訪問共存

          "配置虛主機"中介的方式配置虛主機以后,會發現如果用http://<ip>:<port>/xxx的方式無法訪問DocumentRoot/usr/local/nginx/html)下的用。

          解決方法:

          /usr/local/nginx/conf/vhost/下建立一個新的配置文件 localhost.conf(可以copy其他的vhost配置文件),要改的地方如下

          vim /usr/local/nginx/conf/vhost/ localhost.conf

          <pre>

          ……

          server_name  localhost;

          ……

          root   /usr/local/nginx/html;

          ……

          </pre>

          如果需要支持PHP

          <pre>

          location ~ .*\.(php|php5|php4|shtml|xhtml|phtml)?$ {

           

          fastcgi_pass   127.0.0.1:9000;

           

          fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html/$fastcgi_script_name;

           

          include /usr/local/nginx/conf/fastcgi_params;

           

          }

          ……

          </pre>

          posted on 2012-01-18 21:45 大鳥 閱讀(498) 評論(0)  編輯  收藏 所屬分類: linux
          主站蜘蛛池模板: 阜新市| 和平县| 雅江县| 清涧县| 施秉县| 斗六市| 淮南市| 天祝| 安化县| 唐山市| 石棉县| 香格里拉县| 高密市| 平潭县| 德化县| 郯城县| 卢氏县| 清丰县| 泰州市| 察哈| 宜兰县| 蒙山县| 禹州市| 侯马市| 崇文区| 天柱县| 沁水县| 天全县| 安图县| 巫山县| 翁牛特旗| 卓尼县| 锡林郭勒盟| 稷山县| 孟州市| 璧山县| 雅安市| 两当县| 台湾省| 楚雄市| 红原县|