nginx 의 실천 총화 1

1. nginx 의 설치 스 크 립 트 를 통 해 nginx 의 설 치 를 설명 합 니 다.

  
  
  
  
  1. #!/bin/bash
  2. #author zhangyifei
  3. #2013 2.27
  4. #email [email protected]
  5. #
  6. cd /usr/local/src
  7. wget http://down1.chinaunix.net/distfiles/nginx-1.2.5.tar.gz
  8. wget http://down1.chinaunix.net/distfiles/pcre-8.30.tar.bz2
  9. #pcre nginx rewiter
  10. tar jxvf pcre-8.30.tar.bz2
  11. cd pcre-8.30
  12. ./configure
  13. make && make install
  14. cd ..
  15. pcredir="pcre-8.30"
  16. soft="nginx-1.2.5.tar.gz"
  17. softdir="nginx-1.2.5"
  18. if [ -f $soft ]; then
  19.    tar zxvf $soft
  20. else
  21.    echo "$soft not exis"
  22.    exit
  23. fi
  24. # ssl status
  25. read -p "do you install http_stub_status_module [Y/N]" args1
  26. echo "$args1"
  27. while [ "$args1" != "Y" ] && [ "$args1" != "y" ] && [ "$args1" != "N" ] && [ "$args1" != "n" ]
  28. do
  29.    read -p "please input  [Y/N]" args1
  30. done
  31.  
  32. if [ "$args1" == "Y" ] || [ "$args1" == "y" ]; then
  33.    args1="--with-http_stub_status_module"
  34. else
  35.    args1=""
  36. fi
  37. echo "$args1"
  38. read -p "do you install --with-http_ssl_module [Y/N]" args2
  39. while [ "$args2" != "Y" ] && [ "$args2" != "y" ] && [ "$args2" != "N" ] && [ "$args2" != "n" ]
  40. do
  41.    read -p "please input  [Y/N]" args2
  42. done
  43. echo "$args2"
  44. if [ "$args2" == "Y" ] || [ "$args2" == "y" ]; then
  45.    args2="--with-http_ssl_module"
  46. else
  47.    args2=""
  48. fi
  49. echo "$args2"
  50. # nginx
  51. nginxuser="nginx"
  52. useradd -s /sbin/nolgin $nginxuser
  53. cd $softdir
  54. ./configure --prefix=/usr/local/nginx \
  55. --user=$nginxuser \
  56. --group=$nginxuser \
  57. --with-pcre=/usr/local/src/$pcredir \
  58. $args1 $args2
  59.  
  60. make && make install

2. nginx 의 기본 설정 파일 설명

  
  
  
  
  1. #user  nobody;  nginx
  2. worker_processes  1;  nginx cpu
  3.  
  4. #error_log  logs/error.log;
  5. #error_log  logs/error.log  notice;
  6. #error_log  logs/error.log  info;
  7.  
  8. #pid        logs/nginx.pid; ID
  9.  
  10.  
  11. events {
  12.     worker_connections  1024; worker process
  13. use epoll; epoll nginx
  14. }
  15.  
  16.  
  17. http {
  18.     include       mime.types; html text/html
  19.     default_type  application/octet-stream;
  20.  
  21.     #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  22.     #                  '$status $body_bytes_sent "$http_referer" '
  23.     #                  '"$http_user_agent" "$http_x_forwarded_for"';
  24.  
  25.     #access_log  logs/access.log  main;
  26. sendfile nginx sendfile (zero copy ) , ,
    on, IO , off, I/O , uptime
  27.     sendfile        on; 
  28.     #tcp_nopush     on;
  29.  
  30.     #keepalive_timeout  0;
  31.     keepalive_timeout  65; keepalive
  32.  
  33.     #gzip  on; gzip
  34.  
  35.     server {
  36.         listen       80; 
  37.         server_name  localhost; 
  38.  
  39.         #charset koi8-r;
  40.  
  41.         #access_log  logs/host.access.log  main;
  42.  
  43.         location / {
  44.             root   html; 
  45.             index  index.html index.htm;
  46.         }
  47.  
  48.         #error_page  404              /404.html;
  49.  
  50.         # redirect server error pages to the static page /50x.html
  51.         #
  52.         error_page   500 502 503 504  /50x.html;
  53.         location = /50x.html {
  54.             root   html;
  55.         }
  56. }
  57. }

좋은 웹페이지 즐겨찾기