Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1155908
  • 博文数量: 150
  • 博客积分: 2739
  • 博客等级: 少校
  • 技术积分: 2392
  • 用 户 组: 普通用户
  • 注册时间: 2010-12-07 12:28
文章分类

全部博文(150)

文章存档

2015年(2)

2014年(16)

2013年(10)

2012年(58)

2011年(64)

分类: LINUX

2011-09-17 21:32:21

nginx:     功能:web服务,web代理 ,smtp反向代理
  1. yum install gcc openssl-devel pcre-devel zlib-devel
  2. groupadd nginx
  3. useradd –g nginx –s /bin/false –M nginx
  1. # tar xvf nginx-1.1.3.tar.gz
  2. #cd nginx-1.1.3.tar.gz
  3. # ./configure \
  4.   --prefix=/usr \
  5.   --sbin-path=/usr/sbin/nginx \
  6.   --conf-path=/etc/nginx/nginx.conf \
  7.   --error-log-path=/var/log/nginx/error.log \
  8.   --http-log-path=/var/log/nginx/access.log \
  9.   --pid-path=/var/run/nginx/nginx.pid \
  10.   --lock-path=/var/lock/nginx.lock \
  11.   --user=nginx \
  12.   --group=nginx \
  13.   --with-http_ssl_module \
  14.   --with-http_flv_module \
  15.   --with-http_stub_status_module \
  16.   --with-http_gzip_static_module \
  17.   --http-client-body-temp-path=/var/tmp/nginx/client/ \
  18.   --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  19.   --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  20.   --with-pcre 支持Perl
若要其他的可以用./configure –help
  1. #make
  2.  #make install
安装好后启动nginx,由于启动时没有脚本自己写放在/etc/init.d/:
  1. #!/bin/sh
  2. #
  3. # nginx - this script starts and stops the nginx daemon
  4. #
  5. # chkconfig: - 85 15
  6. # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
  7. # proxy and IMAP/POP3 proxy server
  8. # processname: nginx
  9. # config: /etc/nginx/nginx.conf
  10. # config: /etc/sysconfig/nginx
  11. # pidfile: /var/run/nginx.pid
  12.  
  13. # Source function library.
  14. . /etc/rc.d/init.d/functions
  15.  
  16. # Source networking configuration.
  17. . /etc/sysconfig/network
  18.  
  19. # Check that networking is up.
  20. [ "$NETWORKING" = "no" ] && exit 0
  21.  
  22. nginx="/usr/sbin/nginx"
  23. prog=$(basename $nginx)
  24.  
  25. NGINX_CONF_FILE="/etc/nginx/nginx.conf"
  26.  
  27. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  28.  
  29. lockfile=/var/lock/subsys/nginx
  30.  
  31. make_dirs() {
  32.    # make required directories
  33.    user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
  34.    options=`$nginx -V 2>&1 | grep 'configure arguments:'`
  35.    for opt in $options; do
  36.        if [ `echo $opt | grep '.*-temp-path'` ]; then
  37.            value=`echo $opt | cut -d "=" -f 2`
  38.            if [ ! -d "$value" ]; then
  39.                # echo "creating" $value
  40.                mkdir -p $value && chown -R $user $value
  41.            fi
  42.        fi
  43.    done
  44. }
  45.  
  46. start() {
  47.     [ -x $nginx ] || exit 5
  48.     [ -f $NGINX_CONF_FILE ] || exit 6
  49.     make_dirs
  50.     echo -n $"Starting $prog: "
  51.     daemon $nginx -c $NGINX_CONF_FILE
  52.     retval=$?
  53.     echo
  54.     [ $retval -eq 0 ] && touch $lockfile
  55.     return $retval
  56. }
  57.  
  58. stop() {
  59.     echo -n $"Stopping $prog: "
  60.     killproc $prog -QUIT
  61.     retval=$?
  62.     echo
  63.     [ $retval -eq 0 ] && rm -f $lockfile
  64.     return $retval
  65. }
  66.  
  67. restart() {
  68.     configtest || return $?
  69.     stop
  70.     sleep 1
  71.     start
  72. }
  73.  
  74. reload() {
  75.     configtest || return $?
  76.     echo -n $"Reloading $prog: "
  77.     killproc $nginx -HUP
  78.     RETVAL=$?
  79.     echo
  80. }
  81.  
  82. force_reload() {
  83.     restart
  84. }
  85.  
  86. configtest() {
  87.   $nginx -t -c $NGINX_CONF_FILE
  88. }
  89.  
  90. rh_status() {
  91.     status $prog
  92. }
  93.  
  94. rh_status_q() {
  95.     rh_status >/dev/null 2>&1
  96. }
  97.  
  98. case "$1" in
  99.     start)
  100.         rh_status_q && exit 0
  101.         $1
  102.         ;;
  103.     stop)
  104.         rh_status_q || exit 0
  105.         $1
  106.         ;;
  107.     restart|configtest)
  108.         $1
  109.         ;;
  110.     reload)
  111.         rh_status_q || exit 7
  112.         $1
  113.         ;;
  114.     force-reload)
  115.         force_reload
  116.         ;;
  117.     status)
  118.         rh_status
  119.         ;;
  120.     condrestart|try-restart)
  121.         rh_status_q || exit 0
  122.             ;;
  123.     *)
  124.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  125.         exit 2
  126. esac

保存设置执行权限

  1. #chown +x /etc/init.d/ngixd

  1. 配置文件介绍:


  2. #user nobody;
  3. worker_processes 1; CPU核数有关,能增强并行处理能力
  4. #error_log logs/error.log; 错误日志
  5. #error_log logs/error.log notice; 不同级别的错误日志
  6. #error_log logs/error.log info;
  7. #pid logs/nginx.pid;
  8. events { 允许并发连接数
  9. worker_connections 1024; 最大连接数
  10. }
  11. http {
  12. include mime.types;
  13. default_type application/octet-stream;
  14. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. # '$status $body_bytes_sent "$http_referer" '
  16. # '"$http_user_agent" "$http_x_forwarded_for"';
  17. #access_log logs/access.log main;
  18. sendfile on; 针对小文件访问,有良好的速率
  19. #tcp_nopush on;
  20. #keepalive_timeout 0;
  21. keepalive_timeout 65; 超时时间
  22. #gzip on; 压缩传输
  23. server { 单独定义主机,也可以定义虚拟主机
  24. listen 80;
  25. server_name localhost; 主机名
  26. #charset koi8-r;
  27. #access_log logs/host.access.log main;
  28. location / { 定义在哪个目录设置访问匹配权限
  29. root html; 网页在html子目录下
  30. index index.html index.htm;
  31. }
  32. #error_page 404 /404.html;
  33. # redirect server error pages to the static page /50x.html
  34. #
  35. error_page 500 502 503 504 /50x.html;
  36. location = /50x.html {
  37. root html;
  38. }
  39. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  40. #
  41. #location ~ \.php$ {
  42. # proxy_pass
  43. #}
  44. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  45. #
  46. #location ~ \.php$ {
  47. # root html;
  48. # fastcgi_pass 127.0.0.1:9000;
  49. # fastcgi_index index.php;
  50. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  51. # include fastcgi_params;
  52. #}
  53. # deny access to .htaccess files, if Apache's document root
  54. # concurs with nginx's one
  55. #
  56. #location ~ /\.ht {
  57. # deny all;
  58. #}
  59. }
  60. # another virtual host using mix of IP-, name-, and port-based configuration
  61. #
  62. #server {
  63. # listen 8000;
  64. # listen somename:8080;
  65. # server_name somename alias another.alias;
  66. # location / {
  67. # root html;
  68. # index index.html index.htm;
  69. # }
  70. #}
  71. # HTTPS server
  72. #
  73. #server {
  74. # listen 443;
  75. # server_name localhost;
  76. # ssl on;
  77. # ssl_certificate cert.pem;
  78. # ssl_certificate_key cert.key;
  79. # ssl_session_timeout 5m;
  80. # ssl_protocols SSLv2 SSLv3 TLSv1;
  81. # ssl_ciphers HIGH:!aNULL:!MD5;
  82. # ssl_prefer_server_ciphers on;
  83. # location / {
  84. # root html;
  85. # index index.html index.htm;
  86. # }
  87. #}
  88. }

介绍一些其他的upstream反向代理

  1. upstream name {
  2.                  server IP:80 weight=3;
  3.                  server IP:80 ;
  4.                 }

location 某个网页位置中的某个文件的访问权限

      location [ =|~|~*|^~|@]

          =表示精确匹配

          不带任何符号模糊匹配

          ~ 区分大小写的正则表达式

         ~* 不区分大小写正则表达式

          ^~ 禁用正则表达式

      对于特定子目录的优先级高

What is FastCGIFastCGI

    is a high-speed and scalable interface for communicating with the web server scripting language. FastCGI is supported by many scripting languages, including php, if it is compiled with the option - --enable-fastcgi. It is supported by most popular web servers, including Apache (mod_fastcgi and mod_fcgid), Zeus, nginx and lighttpd. The main advantage of FastCGI is isolating the dynamic language from the web server. The technology, among other things, allows you to run a web server and dynamic language for the different hosts, which improves scalability and also aids security without a significant loss of productivity.PHP-FPM works on with any web server that supports FastCGI.

启动服务:service ngixd start 其中ngixd是编写的脚步的名字
  1. [root@squid2 nginx]# netstat -ntulp |grep nginx
  2.   tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 12713/nginx.conf
压力测试



阅读(967) | 评论(0) | 转发(0) |
0

上一篇:corosync, drbd的配置

下一篇:win8 下载地址

给主人留下些什么吧!~~