您的位置:首页 > 运维架构 > Nginx

nginx基础配置

2011-12-08 10:38 387 查看
1.安装 nginx

在安装之前首先要安装pcre-7.9.tar.gz

    # tar zxvf pcre-7.9.tar.gz  

    # cd pcre-7.9  

    # ./configure  

    # make && make install

安装nginx

     # tar zxvf nginx-0.7.61.tar.gz  

    # cd nginx-0.7.61  

    # ./configure --with-http_stub_status_module --prefix=/usr/local/nginx  

    # make && make install

修改nginx的配置文件

我这里是把原先的重命名然后新建了一个nginx.conf

#############################################

    #vi nginx.conf  

    user nobody nobody;  

    worker_processes   8;  

    pid   /usr/local/nginx/logs/nginx.pid;  

    worker_rlimit_nofile 51200;  

    events  

   

Unknown macro: {      use epoll;      worker_connections 51200;      }

 

    http{  

    include mime.types;  

    default_type   application/octet-stream;  

    server_names_hash_bucket_size 128;  

    client_header_buffer_size 32k;  

    large_client_header_buffers 4 32k;  

    client_max_body_size 8m;  

     

    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;  

    #设定负载均衡列表    

    upstream   backend  

   

Unknown macro: {        hash_ip    server 192.168.100.89}

 

    #设定虚拟主机  

    server {  

    listen 80;  

    server_name  www.www.tenddata.com.com;  

    #对 / 所有做负载均衡 (本机nginx采用完全转发,所有请求都转发到后端的tomcat集群)  

    location /

Unknown macro: {        root /var/www ;      index index.jsp index.htm index.html;      proxy_redirect off;      #保留用户真实信息      proxy_set_header Host $host;      proxy_set_header   X-Real-IP   $remote_addr;      proxy_set_header  
X-Forwarded-For $proxy_add_x_forwarded_for;      proxy_pass  http}
 

     

    #location /nginx

Unknown macro: {        #access_log   on;      #auth_basic   "NginxStatus";      #auth_basic_user_file   /usr/local/nginx/htpasswd;      #}

 

    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   /var/log/access.log   access;  

    }  

    }  

###################################################################

检查nginx的配置文件

# /usr/local/webserver/nginx/sbin/nginx -t

启动nginx

# /usr/local/webserver/nginx/sbin/nginx

重启nginx

# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`

(1)查看负载均衡信息

    location /nginx

Unknown macro: {        stub_status on;      access_log   on;      auth_basic   "NginxStatus";      auth_basic_user_file   /usr/local/nginx/htpasswd;      }

 

其中/usr/local/nginx/htpasswd可以用apache自带的功能生成。

最后在IE里访问:

http://www.tenddata.com/nginx, 然后输入用户名密码就进入了。

进入之后的说明

输入地址 http://www.tenddata.com/nginx/,输入验证帐号密码,即可看到类似如下内容:
    Active connections: 328  

    server accepts handled requests  

    9309 8982   28890  

    Reading: 1 Writing: 3 Waiting: 324  

第一行表示目前活跃的连接数

第三行的第三个数字表示Nginx运行到当前时间接受到的总请求数,如果快达到了上限,就需要加大上限值了。

第四行是Nginx的队列状态

(2)负载均衡

    upstream   backend  

   

Unknown macro: {        server 192.168.100.89}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息