Nginx生产环境安装配置

不建议使用nginx-1.18.0.tar.gz,因为扫出很多漏洞

上传nginx-1.24.0.tar.gz

[root@zonghe01 data]# ll
-rw-r--r--  1 root root 1112471 Oct 26 15:57 nginx-1.24.0.tar.gz
[root@zonghe01 data]# pwd
/data

解押

[root@zonghe01 data]# tar -zxvf nginx-1.24.0.tar.gz

配置、编译、安装

[root@zonghe01 data]# cd nginx-1.24.0
[root@zonghe01 nginx-1.24.0]# pwd
/data/nginx-1.24.0
[root@zonghe29 nginx-1.24.0]# ./configure --prefix=/data/nginx24
[root@zonghe29 nginx-1.24.0]# make
[root@zonghe29 nginx-1.24.0]# make install

上传配置文件到指定文件夹下(base.conf、xxx.conf、nginx.conf)

/data/nginx24/conf下建立文件夹config和vhost
[root@zonghe01 config]# ll
total 4
-rw-r--r-- 1 root root 1317 Jun 19 09:01 base.conf
[root@zonghe01 config]# pwd
/data/nginx24/conf/config
[root@zonghe01 config]# cd ../vhost/
[root@zonghe01 vhost]# ll
total 12
-rw-r--r-- 1 root root 2723 Nov 17 10:43 xxx.conf
-rw-r--r-- 1 root root  257 Nov 14 11:08 minio.conf

base.conf文件内容

#配置nginx高效的文件传输模式
sendfile        on;
keepalive_timeout  75s;
#隐藏nginx header版本号,默认为on开启
server_tokens off;
#支持请求头参数的下划线,默认为off关闭,请求中的下划线将会被去掉再不往下传递
underscores_in_headers on;
#设置最大上传文件,默认值为1m,可单独在server,location中设置
client_max_body_size  100m;
#请求头的超时时间,默认60s
client_header_timeout 60s;
client_body_timeout 60s;
#配置缓冲区,线上环境优化重点
proxy_buffering on;
proxy_buffer_size 4k;
proxy_buffers 2 4k;
proxy_busy_buffers_size 4k;
proxy_max_temp_file_size 20M;
proxy_temp_file_write_size 8k;
proxy_connect_timeout 60s;
proxy_read_timeout 1m;
proxy_send_timeout 1m;

gzip on;
#gzip_static on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
#gzip_types text/plain application/x-javascript text/css application/xml;
gzip_types text/plain application/javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg  image/gif image/png;
gzip_vary on;
gzip_proxied   expired no-cache no-store private auth;
gzip_disable   "MSIE [1-6]\.";

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

xxx.conf文件内容

upstream http_res{
        server xxx.18.xxx.xxx:80;
        server xxx.18.xxx.xxx:81;
        server xxx.18.xxx.xxx:82;
}
server {
        listen       80;
        server_name xxx.xxx.251.xxx;
        #location / {
         #   root   html;
          #  index  index.html index.htm;
        #}
         location  /audit/ {
          alias /data/web/audit/xxx_web/;
          index index.html /data/web/audit/xxx_web/index.html;
        }
	location /minio/ {
		#proxy_http_version 1.1;
    		#proxy_set_header Upgrade $http_upgrade;
    		#proxy_set_header Connection "upgrade";
	        #proxy_set_header   Host 172.19.57.11;  		
                proxy_pass http://127.0.0.1:9001/;
	}

	 location /api2/ {
			proxy_pass http://http_res;
			proxy_http_version 1.1;
			proxy_set_header   Host $http_host;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
	}
	 location /api/ {
			proxy_pass http://http_res;
			proxy_http_version 1.1;
			proxy_set_header   Host $http_host;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
	}
 }

nginx.conf文件内容

user  root;
# 跟服务器核数相同
worker_processes  8;

events {
    worker_connections  4096;
    #worker_rlimit_nofile 65535;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    include config/base.conf;
    server_names_hash_bucket_size 64;
    charset utf-8;
    send_timeout 120s;
    # 读取vhost下所有.conf文件
    include vhost/*.conf;
}

启动、停止、重启

[root@zonghe02 conf]# /data/nginx24/sbin/nginx
[root@zonghe02 conf]# /data/nginx24/sbin/nginx -s stop
[root@zonghe02 conf]# /data/nginx24/sbin/nginx -s reload
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值