配置文件优化,启用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;
}
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