• nginx安装和使用


    1.安装参考
    # 解决 ./configure: error: C compiler cc is not found
    # 或者 make: *** No rule to make target `build', needed by `default'. Stop.
    # 或者 新机器安装nginx,在make编译是报错:
    # 注意 需要删除原来configure的那个目录
    sudo yum install -y gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel autoconf automake make gd gd-devel
    
    • 1
    • 2
    • 3
    • 4
    • 5
    2.安装gzip
    # 参考文档:https://blog.csdn.net/biraotian/article/details/117084463
    ./configure --prefix=/usr/local/nginx --with-http_gzip_static_module
    
    • 1
    • 2
    3.http中添加log_format
    log_format log_json '{"time_local": "$time_iso8601", '
                            '"remote_addr": "$remote_addr", '
                            '"remote_user": "$remote_user", '
                            '"http_referer": "$http_referer", '
                            '"request": "$request", '
                            '"status": $status, '
                            '"body_bytes_sent": $body_bytes_sent, '
                            '"http_user_agent": "$http_user_agent", '
                            '"http_x_forwarded_for": "$http_x_forwarded_for", '
                            '"upstream_addr": "$upstream_addr",'
                            '"upstream_connect_time": "$upstream_connect_time",'
                            '"upstream_response_time": "$upstream_response_time",'
                            '"upstream_header_time": "$upstream_header_time",'
                            '"upstream_http_host": "$upstream_http_host",'
                            '"request_time": "$request_time"'
                            ' }';
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    4.对应服务映射的模板样例

    注意:需要在http中引入该配置 ===> include /usr/local/nginx/conf/openapi.conf;

    server {
        listen 9004;
        server_name localhost;
    
        location / {
            proxy_pass http://app_electronic_letter/;
            proxy_set_header Host $host:$server_port;
            proxy_set_header user-agent $http_user_agent;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            client_max_body_size 100m;
            client_body_buffer_size 1280k;
            proxy_connect_timeout 5s;
            proxy_send_timeout 900s;
            proxy_read_timeout 900s;
            proxy_buffering off;
            proxy_temp_file_write_size 640k;
            proxy_redirect off;
        }
            
    }
    
    upstream app_electronic_letter {
        server 172.17.9.13:9004 weight=1;
        server 172.17.9.14:9004 weight=1;
    }
    
    • 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
    5.常用命令
    # 查看nginx版本
    nginx -v
    
    # 检测nginx的配置文件
    nginx -t
    
    # 平滑重启:不会强制结束正在工作的连接,需要等所有连接都结束才会重启
    nginx -s reload
    
    # 指定配置文件启动,也可以不指定,使用默认的nginx.conf
    nginx -c /etc/nginx/nginx.conf
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  • 相关阅读:
    SpringCloud使用注解+AOP+MQ来实现日志管理模块
    操作系统computer operate system
    Canal使用和安装总结
    Google guava之Multiset简介说明
    uniapp web-view调整修改高度设置
    zookeeper的基本概念
    [安卓android毕业设计]精品基于Uniapp+SSM实现的校园心理健康APP[源码]
    [python][labelme]labelme中默认颜色
    阿里云安装软件:jdk11
    在QML委托代理机制中使用C++数据模型
  • 原文地址:https://blog.csdn.net/zj20142213/article/details/133775447