nginx1.10.3一键安装/系统内核优化/配置文件优化/https/日志切割

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 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
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
75
76
77
78
79
80
下面的是一键安装nginx 1.10.3 最新稳定版本,编译参数是官方推荐的。
 
yum groupinstall  "Development Tools"    -y
yum   install  wget   zlib-devel openssl-devel pcre-devel -y
cd  /usr/local/src
wget http: //nginx .org /download/nginx-1 .10.3. tar .gz
tar  zxvf nginx-1.10.3. tar .gz
cd  nginx-1.10.3
groupadd -g 58 nginx
useradd  -u 58 -g 58 -M nginx -s  /sbin/nologin
mkdir  -p  /var/tmp/nginx/ {client,proxy,fastcgi,uwsgi,scgi}
mkdir  -p  /var/cache/nginx/client_temp
. /configure  \
--user=nginx --group=nginx \
--prefix= /etc/nginx    \
--sbin-path= /usr/sbin/nginx  \
--conf-path= /etc/nginx/nginx .conf \
--error-log-path= /var/log/nginx/error .log \
--http-log-path= /var/log/nginx/access .log \
--pid-path= /var/run/nginx .pid \
--lock-path= /var/run/nginx .lock \
--http-client-body-temp-path= /var/cache/nginx/client_temp  \
--http-proxy-temp-path= /var/cache/nginx/proxy_temp  \
--http-fastcgi-temp-path= /var/cache/nginx/fastcgi_temp  \
--http-uwsgi-temp-path= /var/cache/nginx/uwsgi_temp  \
--http-scgi-temp-path= /var/cache/nginx/scgi_temp  \
--user=nginx \
--group=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_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_slice_module \
--with-mail \
--with-mail_ssl_module \
--with- file -aio \
--with-http_v2_module \
--with-ipv6
make  &&  make  install
nginx -V
  
  
Centos7 启动方式
 
cat   >>  /lib/systemd/system/nginx .service  <<EOF
[Unit]
Description=nginx - high performance web server
Documentation=http: //nginx .org /en/docs/
After=network.target remote-fs.target nss-lookup.target
   
[Service]
Type=forking
PIDFile= /run/nginx .pid
ExecStartPre= /usr/sbin/nginx  -t -c  /etc/nginx/nginx .conf
ExecStart= /usr/sbin/nginx  -c  /etc/nginx/nginx .conf
ExecReload= /bin/kill  -s HUP $MAINPID
ExecStop= /bin/kill  -s QUIT $MAINPID
PrivateTmp= true
   
[Install]
WantedBy=multi-user.target
EOF
 
 
 
systemctl  enable  nginx.service
systemctl start  nginx.service
netstat  -lntup  |  grep  80
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
内核优化  
 
cat    >>   /etc/sysctl .conf << EOF
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets = 6000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rmem = 4096        87380   4194304
net.ipv4.tcp_wmem = 4096        16384   4194304
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.netdev_max_backlog = 262144
net.core.somaxconn = 262144
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_fin_timeout = 1
net.ipv4.tcp_keepalive_time = 30
net.ipv4.ip_local_port_range = 1024    6500
EOF
1
2
3
sysctl -p
cd  /etc/nginx/
mv  nginx.conf nginx.conf.bak
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
配置文件优化,启用HTTPS
 
vim nginx.conf
user  nginx nginx;
worker_processes  auto;
worker_rlimit_nofile 65535;
 
error_log   /var/log/nginx/error .log  info;
pid         /var/run/nginx .pid;
 
events {
     use epoll;
     worker_connections 10240;
     multi_accept on;
}
 
http
     {
     include       mime.types;
     default_type  application /octet-stream ;
 
     charset  utf-8;
 
     log_format  main   '$remote_addr - $remote_user [$time_local] "$request" '
                       '$status $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"' ;
 
     access_log   /var/log/nginx/access .log  main;
 
     server_names_hash_bucket_size 128;
     client_header_buffer_size 16k;
     large_client_header_buffers 4 16k;
     client_max_body_size 50m;
 
     server_tokens off;
     autoindex off;
 
     sendfile on;
     tcp_nopush     on;
 
     keepalive_timeout 60;
     tcp_nodelay  on;
     client_header_timeout 15;
     reset_timedout_connection on;
     client_body_timeout 15;
     send_timeout 15;
 
   
     
     fastcgi_intercept_errors on;
 
     fastcgi_connect_timeout 300;
     fastcgi_send_timeout 300;
     fastcgi_read_timeout 300;
     fastcgi_buffer_size 16k;
     fastcgi_buffers 16 16k;
     fastcgi_busy_buffers_size 16k;
     fastcgi_temp_file_write_size 16k;
 
     fastcgi_cache_path  /etc/nginx/fastcgi_cache  levels=1:2
                     keys_zone=TEST:10m
                     inactive=5m;
 
     fastcgi_cache TEST;
     fastcgi_cache_valid 200 302 1h;
     fastcgi_cache_valid 301 1d;
     fastcgi_cache_valid any 1m;
     fastcgi_cache_min_uses 1;
     fastcgi_cache_use_stale error timeout invalid_header http_500;
     fastcgi_cache_key  "$request_method://$host$request_uri" ;
 
     open_file_cache max=204800 inactive=20s;
     open_file_cache_min_uses 1;
     open_file_cache_valid 30s;
 
     gzip  on;
     gzip_min_length  1k;
     gzip_buffers     4 16k;
     gzip_http_version 1.1;
     gzip_comp_level 5;
     gzip_types       text /css  application /javascript   text /xml ;
     gzip_vary on;
     gzip_disable  "MSIE [1-6].(?!.*SV1)" ;
 
 
     server
         {
         listen       80;
         server_name  hequan.lol;
         index index.php index.html  index.htm;
         root html;
 
         return          301 https: // $server_name$request_uri;
 
     }
 
     server {
         listen 443  ssl;
         server_name hequan.lol;
         index index.html index.htm index.php default.html default.htm default.php;
 
         root  html;
 
         ssl on;
         ssl_certificate       /etc/nginx/key/1_www .hequan.lol_bundle.crt;
         ssl_certificate_key   /etc/nginx/key/2_www .hequan.lol.key;
 
         ssl_ciphers  "EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5" ;
         ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
         ssl_prefer_server_ciphers on;
         ssl_session_cache shared:SSL:10m;
 
         location  /status
             {
             stub_status on;
             access_log off;
             #allow 127.0.0.1;
             #deny all;
         }
 
         error_page  400 401 402 403 404   /40x .html;
         location =  /40x .html {
                 root  html;
                 index  index.html index.htm;
         }
 
         error_page  500 501 502 503 504   /50x .html;
         location =  /50x .html {
             root  html;
             index  index.html index.htm;
         }
 
         
         location ~ \.php$ {
             root           html;
             fastcgi_pass   127.0.0.1:9000;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME   /etc/nginx/html $fastcgi_script_name;
             include        fastcgi_params;
         }
 
         location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
             {
             expires 30d;
         }
 
         location ~ .*\.(js|css)?$
             {
             expires 12h;
         }
     }
}
 
 
 
日志切割
 
cat  >> log.sh <<EOF
#!/bin/bash
path= /var/log/nginx/backup
if  [ ! -d   "#path"   ];  then
     mkdir  -p $path
fi
cd   /var/log/nginx
mv  access.log   backup/$( date  +%F -d -1day).log
systemctl reload  nginx.service
EOF
 
 
crontab  -e
00 00 * * *  /var/log/nginx/log .sh  >  /dev/null  2&1

关于证书  可以去

https://console.qcloud.com/ssl/apply  (有效期一年) 申请,非常简单。腾讯认证的。跟着流程走,几分钟就好。

1
2
ssl_certificate       /etc/nginx/key/1_www .hequan.lol_bundle.crt;   
ssl_certificate_key   /etc/nginx/key/2_www .hequan.lol.key;

上面一个是证书,一个是密钥。自定义目录。



以上设置仅供参考。欢迎提出有疑问的地方。










本文转自 295631788 51CTO博客,原文链接:http://blog.51cto.com/hequan/1895932,如需转载请自行联系原作者
相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
7天前
|
存储 安全 Java
Spring Boot 3 集成Spring AOP实现系统日志记录
本文介绍了如何在Spring Boot 3中集成Spring AOP实现系统日志记录功能。通过定义`SysLog`注解和配置相应的AOP切面,可以在方法执行前后自动记录日志信息,包括操作的开始时间、结束时间、请求参数、返回结果、异常信息等,并将这些信息保存到数据库中。此外,还使用了`ThreadLocal`变量来存储每个线程独立的日志数据,确保线程安全。文中还展示了项目实战中的部分代码片段,以及基于Spring Boot 3 + Vue 3构建的快速开发框架的简介与内置功能列表。此框架结合了当前主流技术栈,提供了用户管理、权限控制、接口文档自动生成等多项实用特性。
38 8
|
1月前
|
监控 应用服务中间件 定位技术
要统计Nginx的客户端IP,可以通过分析Nginx的访问日志文件来实现
要统计Nginx的客户端IP,可以通过分析Nginx的访问日志文件来实现
116 3
|
1月前
|
存储 监控 安全
什么是事件日志管理系统?事件日志管理系统有哪些用处?
事件日志管理系统是IT安全的重要工具,用于集中收集、分析和解释来自组织IT基础设施各组件的事件日志,如防火墙、路由器、交换机等,帮助提升网络安全、实现主动威胁检测和促进合规性。系统支持多种日志类型,包括Windows事件日志、Syslog日志和应用程序日志,通过实时监测、告警及可视化分析,为企业提供强大的安全保障。然而,实施过程中也面临数据量大、日志管理和分析复杂等挑战。EventLog Analyzer作为一款高效工具,不仅提供实时监测与告警、可视化分析和报告功能,还支持多种合规性报告,帮助企业克服挑战,提升网络安全水平。
|
2月前
|
安全 应用服务中间件 网络安全
49.3k star,本地 SSL 证书生成神器,轻松解决 HTTPS 配置痛点
mkcert是一款由Filippo Valsorda开发的免费开源工具,专为生成受信任的本地SSL/TLS证书而设计。它通过简单的命令自动生成并安装本地信任的证书,使本地环境中的HTTPS配置变得轻松无比。mkcert支持多个操作系统,已获得49.2K的GitHub Star,成为开发者首选的本地SSL工具。
184 10
|
3月前
|
负载均衡 应用服务中间件 Linux
nginx学习,看这一篇就够了:下载、安装。使用:正向代理、反向代理、负载均衡。常用命令和配置文件,很全
这篇博客文章详细介绍了Nginx的下载、安装、配置以及使用,包括正向代理、反向代理、负载均衡、动静分离等高级功能,并通过具体实例讲解了如何进行配置。
203 4
nginx学习,看这一篇就够了:下载、安装。使用:正向代理、反向代理、负载均衡。常用命令和配置文件,很全
|
2月前
|
存储 Linux Docker
centos系统清理docker日志文件
通过以上方法,可以有效清理和管理CentOS系统中的Docker日志文件,防止日志文件占用过多磁盘空间。选择合适的方法取决于具体的应用场景和需求,可以结合手动清理、logrotate和调整日志驱动等多种方式,确保系统的高效运行。
224 2
|
3月前
|
XML JSON 监控
告别简陋:Java日志系统的最佳实践
【10月更文挑战第19天】 在Java开发中,`System.out.println()` 是最基本的输出方法,但它在实际项目中往往被认为是不专业和不足够的。本文将探讨为什么在现代Java应用中应该避免使用 `System.out.println()`,并介绍几种更先进的日志解决方案。
85 1
|
2月前
|
安全 网络协议 网络安全
怎么给ip地址配置https访问
为了配置公网IP地址的HTTPS访问,首先需明确需求并选择受信任的证书颁发机构(如JoySSL)。接着,在JoySSL官网注册并登录,填写特定注册码230922以获取免费IP证书的测试权限。提交证书申请时,填写IP地址及相关验证信息,并完成IP地址验证。验证通过后,下载证书文件。最后,使用浏览器访问IP地址,检查安全连接标志,确保无证书错误。通过以上步骤,可成功配置IP地址的HTTPS访问,提升数据传输安全性和可信度。
|
3月前
|
监控 网络协议 安全
Linux系统日志管理
Linux系统日志管理
74 3
|
3月前
|
监控 应用服务中间件 网络安全
#637481#基于django和neo4j的日志分析系统
#637481#基于django和neo4j的日志分析系统
50 4