Nginx部署

安装依赖

yum -y install gcc gcc-c++ zlib zlib-devel openssl openssl-devel pcre pcre-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel

下载安装nginx

tar -zxf nginx-1.21.4.tar.gz
cd nginx
useradd nginx -s /sbin/nologin

# 编译
./configure \
--user=nginx --group=nginx \
--prefix=/usr/share/nginx \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_perl_module \
--with-mail \
--with-mail_ssl_module \
--with-http_v2_module \
--with-stream \
--with-stream_ssl_module \
--with-http_geoip_module

# 安装
make && make install     #可能会出现无法创建logs目录错误,手动创建即可
cd #/sbin  && ./nginx -t  #测试

nginx配置初始化

user  nginx;
worker_processes  auto;
worker_rlimit_nofile 204800;

events {
    use epoll;
    multi_accept on;
    worker_connections  102400;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    tcp_nopush     on;
    tcp_nodelay on;

    keepalive_timeout  60;

    server_names_hash_bucket_size       128;
    client_header_buffer_size   32k;
    large_client_header_buffers 4       32k;
    client_max_body_size        50m;

    open_file_cache max=102400 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 1;
    send_timeout        300;

    proxy_buffer_size 128k;
    proxy_buffers   32 128k;
    proxy_busy_buffers_size 128k;

    gzip  on;
    gzip_min_length     1k;
    gzip_buffers        4 16k;
    gzip_http_version   1.1;
    gzip_comp_level     2;
    gzip_types  text/plain text/xml application/x-javascript text/css application/xml application/json
    gzip_vary   on;

    server_tokens off;
    fastcgi_intercept_errors on;
    
    set_real_ip_from 100.125.0.0/16;
    real_ip_header X-Forwarded-For;

    log_format main_lb '$remote_addr $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '$http_user_agent $http_x_forwarded_for $request_time $upstream_response_time $upstream_addr $upstream_status';

    include *.cfg;

}
stream {

    log_format proxy '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time "$upstream_addr" '
                 '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';

    access_log logs/nacos.server_tcp-access.log proxy ;
    open_log_file_cache off;
            
    include tcpconf/*.cfg;

}