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

Nginx实现反向代理

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

localhost  反向代理到 s102--s104

 
1.windows下
        安装openresty,并修改nginx.conf配置文件
 
nginx.conf配置文件
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#使用指定用户
#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   
 
 
 
 
 
 
 
 
 
 
 
 
posted @   star521  阅读(278)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
点击右上角即可分享
微信分享提示