Nginx反向代理+负载均衡简单实现(http方式)(4)

--------------------------------------------------------------------------------------
后端机:B机器上的操作记录:
1)编译安装nginx
[root@B ~]# yum install -y pcre* openssl* gcc gcc+
[root@B ~]# cd /opt/src
[root@B ~]# wget
[root@B ~]# tar -zxvf nginx-1.8.0.tar.gz
[root@B ~]# cd nginx-1.8.0
#添加www用户,其中-M参数表示不添加用户家目录,-s参数表示指定shell类型

[root@nginx-1.8.0 ~]#useradd www -M -s /sbin/nologin
[root@nginx-1.8.0 ~]##vim auto/cc/gcc
#将这句注释掉 取消Debug编译模式 大概在179行
#CFLAGS="$CFLAGS -g"

#我们再配置下nginx编译参数
[root@nginx-1.8.0 ~]# ./configure --prefix=/opt/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module
[root@nginx-1.8.0 ~]#make
[root@nginx-1.8.0 ~]#make install clean

2)配置nginx
[root@nginx-1.8.0 ~]# cd /opt/nginx/conf
注意,把默认的nginx.conf文件中的server区域配置注释掉,设置vhosts虚拟主机的配置,如下:
[root@nginx-1.8.0 conf]# vim nginx.conf

user  www;

worker_processes  8;

   

events {

    worker_connections  65535;

}

   

http {

    include      mime.types;

    default_type  application/octet-stream;

    charset utf-8;

  

    log_format  main  '$http_x_forwarded_for $remote_addr $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_cookie" $host $request_time';

    sendfile      on;

    tcp_nopush    on;

    tcp_nodelay    on;

    keepalive_timeout  65;

  

  

    fastcgi_connect_timeout 3000;

    fastcgi_send_timeout 3000;

    fastcgi_read_timeout 3000;

    fastcgi_buffer_size 256k;

    fastcgi_buffers 8 256k;

    fastcgi_busy_buffers_size 256k;

    fastcgi_temp_file_write_size 256k;

    fastcgi_intercept_errors on;

   

      

    client_header_timeout 600s;

    client_body_timeout 600s;

   

    client_max_body_size 100m;           

    client_body_buffer_size 256k;         

   

    gzip  on;

    gzip_min_length  1k;

    gzip_buffers    4 16k;

    gzip_http_version 1.1;

    gzip_comp_level 9;

    gzip_types      text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php;

    gzip_vary on;

   

  

    include vhosts/*.conf;

}

[root@nginx-1.8.0 conf]# ulimit -n 65535
[root@nginx-1.8.0 conf]# mkdir vhosts
[root@nginx-1.8.0 conf]# cd vhosts

[root@nginx-1.8.0 conf]# vim 8080.conf

server {

    listen 8080;

    server_name localhost;

    index index.html index.php index.htm;

  

    access_log  /usr/local/nginx/logs/8080-access.log main;

    error_log  /usr/local/nginx/logs/8080-error.log;

 

location ~ / {

    root /var/www/html/8080;

    index index.html index.php index.htm;

}

}

[root@nginx-1.8.0 conf]# vim 8090.conf

server {

    listen 8090;

    server_name localhost;

    index index.html index.php index.htm;

  

    access_log  /usr/local/nginx/logs/8090-access.log main;

    error_log  /usr/local/nginx/logs/8090-error.log;

 

location ~ / {

    root /var/www/html/8090;        #针对上面匹配ios的path代理,要保证站点目录/var/www/html/8080下有ios目录存在

    index index.html index.php index.htm;

}

}

[root@nginx-1.8.0 conf]# vim 80.conf

server {

   listen 80;

   server_name localhost;

   index index.html index.php index.htm;

  

   access_log  /usr/local/nginx/logs/80-access.log main;

   error_log  /usr/local/nginx/logs/80-error.log;

 

location ~ / {

   root /var/www/html;

   index index.html index.php index.htm;

}

}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/0a4f128b0e00dfe1bf234a6f7b7e3dcc.html