01.友盟项目--nginx服务器配置

Nginx实现反向代理

openresty-nginx增强版(现在使用的)

localhost  反向代理到 s102--s104

 
1.windows下
        安装openresty,并修改nginx.conf配置文件
 
nginx.conf配置文件
 
#使用指定用户
#user  root;
#使用的处理器进程数
worker_processes  4;

#错误日志文件
#error_log  logs/error.log;
#日志文件与日志级别
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#存放进程pid
#pid        /tmp/nginx.pid;


events {
    #每个worker最大连接数
    worker_connections  1024;
}


http {
    include       mime.types;
    #default_type  application/json;
    #default_type  application/octet-stream;
    #文件类型:纯文本
    default_type  text/plain;

    #重点:日志格式
    log_format main escape=json $msec#$clientRealIp#$http_client_time#$status#$request_body;
    #log_format  main  escape=json $clientRealIp#$http_client_time#$time_local#$status#$request_body;

    #自定义变量,取得ip串中的第一个ip,也就是用户ip
    map $http_x_forwarded_for  $clientRealIp {
        ~^(?P<firstAddr>[0-9\.]+),?.*$    $firstAddr;
    }

    #反向代理服务器不需要存储日志
    access_log  off;

    sendfile        on;
    #tcp_nopush     on;
    underscores_in_headers on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    #反向代理服务器:静态服务器
    upstream nginx_servers{
                server s102:8089 max_fails=2 fail_timeout=2 weight=4;
                server s103:8089 max_fails=2 fail_timeout=2 weight=4;
                server s104:8089 max_fails=2 fail_timeout=2 weight=4;
        }

    #server域配置
    server {
                listen       8089;
                server_name  localhost;
                charset utf-8;
                access_log off;
                location ~* \.(png|html|js|css)$ {
                        proxy_pass http://nginx_servers;
                }
                location / {
                        proxy_pass http://nginx_servers;
                }
                proxy_set_header Host $host;
                proxy_set_header remove_user_ip $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

}

2. linux下

 .下载安装linux下的openresty   在s102-s104安装openresty
 
        你可以在你的 CentOS 系统中添加 openresty 仓库,这样就可以便于未来安装或更新我们的软件包(通过 yum update 命令)。运行下面的命令就可以添加我们的仓库:
        sudo yum install -y yum-utils
        sudo yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
 
        然后就可以像下面这样安装软件包,比如 openresty:
        sudo yum install -y  openresty
 
nginx.conf配置文件
s102-s104



user  root;
worker_processes  4;

#pid        /tmp/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    #default_type  application/json;
    #default_type  application/octet-stream;
    default_type  text/plain;
    log_format main escape=json $msec#$clientRealIp#$http_client_time#$status#$request_body;
    #log_format  main  escape=json $clientRealIp#$http_client_time#$time_local#$status#$request_body;
    
    map $http_x_forwarded_for  $clientRealIp {                    
        ~^(?P<firstAddr>[0-9\.]+),?.*$    $firstAddr;
    }  

    access_log  off;

    sendfile        on;
    #tcp_nopush     on;
    underscores_in_headers on;    

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       8089;
        server_name  s102;

        charset utf-8;

        access_log  /usr/local/openresty/nginx/logs/access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
            error_page      405 =200 $1;
            lua_need_request_body   on;
        content_by_lua  'local s = ngx.var.request_body';
        }

    }

}
   3、安装完之后,文件位置在/usr/local/openresty
  4、启动openresty
        windows启动:nginx
        Linux启动:openresty
 
 5.查看日志
 
 
6.清空日志中数据
[root@s101 /home/centos]# xcall.sh "echo -n > /usr/local/openresty/nginx/logs/access.log   
 
 
 
 
 
 
 
 
 
 
 
 

转载于:https://www.cnblogs.com/star521/p/9865322.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值