[root@boke-host ~]# cat /web-boke/nginx/conf/nginx.conf
user nginx;
worker_processes auto;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#error_log /var/log/nginx/error.log warn;
#pid logs/nginx.pid;
events {
use epoll;
worker_connections 65532;
}
http {
include mime.types;
default_type application/octet-stream;
# log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
log_format json '{ "@timestamp": "$time_iso8601", '
#'"server_host":"$server_addr",'
'"server_addr":"223.84.153.80",'
'"http_host":"$http_host",'
'"nginx_version":"$nginx_version",'
'"cdn_ip":"$remote_addr",'
'"remote_user":"$remote_user",'
'"request":"$request",'
'"request_method":"$request_method",'
'"http_user_agent":"$http_user_agent",'
'"size":$body_bytes_sent,'
'"responsetime":$request_time,'
'"upstreamtime":"$upstream_response_time",'
'"upstreamhost":"$upstream_addr",'
'"url":"$uri",'
'"http_x_forwarded_for":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"scheme":"$scheme",'
'"server_protocol":"$server_protocol",'
'"status":"$status"}';
access_log /var/log/nginx/access.log json;
#access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log error;
##这段是加载waf模块
# lua_package_path "/web-boke/nginx/conf/waf/?.lua";
# lua_shared_dict limit 10m;
# init_by_lua_file /web-boke/nginx/conf/waf/init.lua;
# access_by_lua_file /web-boke/nginx/conf/waf/waf.lua;
include /web-boke/nginx-boke/boke-ssl.conf;
sendfile on;
tcp_nopush on;
#告诉nginx在一个数据包里发送所有头文件,而不一个接一个的发送
tcp_nodelay on;
keepalive_timeout 65;
#HTTP连接持续时间,值越大无用的线程变的越多,0:关闭此功能,默认为75
client_header_timeout 10;
client_body_timeout 10;
#以上两项是设置请求头和请求体各自的超时时间
reset_timedout_connection on;
#告诉nginx关闭不响应的客户端连接
send_timeout 30;
#客户端响应超时时间,若客户端停止读取数据,释放过期的客户端连接,默认60s
types_hash_max_size 2048;
server_tokens off; #Nginx打开网页报错时,关闭版本号显示
gzip on;
gzip_min_length 10240;
gzip_buffers 16 8k; #租用16个单位为8k的内存做压缩缓存存储空间
gzip_comp_level 4; #压缩级别1-9,数字越小压缩比越小越快,反之亦然
gzip_proxied expired no-cache no-store private auth;
#一般不对图像和视频进行传输压缩–耗资源效果还不咋地
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
gzip_disable "MSIE [1-6]."; #禁止对IE6进行压缩,因为IE6压缩会导致IE崩溃
}
[root@boke-host ~]# cat /web-boke/nginx-boke/boke-ssl.conf
server {
listen 443 ssl http2 default_server;
root /web-boke/html;
ssl_certificate "/web-boke/ssl-ca/boke.pem";
ssl_certificate_key "/web-boke/ssl-ca/boke.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
location / {
index index.php;
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}
if (!-f $request_filename){
rewrite (.*) /index.php;
}
#这是设置nginx关于wordpress的伪静态
}
#
#禁止Scrapy等工具的抓取
if ($http_user_agent ~* (Scrapy|Curl|Sqlmap|HttpClient)) {
return 403;
}
#禁止指定UA及UA为空的访问
if ($http_user_agent ~* "FeedDemon|Indy Library|Alexa Toolbar|AskTbFXTV|AhrefsBot|CrawlDaddy|CoolpadWebkit|Java|Feedly|UniversalFeedParser|ApacheBench|Microsoft URL Control|Swiftbot|ZmEu|oBot|jaunty|Python-urllib|lightDeckReports Bot|YYSpider|DigExt|HttpClient|MJ12bot|heritrix|EasouSpider|Ezooms|^$" ) {
return 403;
}
#禁止非GET|HEAD|POST方式的抓取
if ($request_method !~ ^(GET|HEAD|POST)$) {
return 403;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~* \.(js|css|png|jpg|jpeg|bmp|gif|ico)$ {
expires max;
log_not_found off;
access_log off;
# Send the all shebang in one fell swoop
tcp_nodelay off;
# Set the OS file cache
open_file_cache max=1000 inactive=120s;
open_file_cache_valid 45s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
#这是静态文件缓存优化
#下面的配置要小心哦,这是防盗链的,可能导致自己的css加载出错哦,要是配置不好
valid_referers none blocked wsfnk.com;
if ($invalid_referer) {
return 403;
#rewrite ^/ https://www.renwole.com
#若不符合条件域名,则返回403或404也可以是域名
}
#这是静态图片文件防盗链
}
location = /wp-login.php {
auth_basic "please admin's koulin";
auth_basic_user_file /web-boke/ssl-ca/login-radius;
fastcgi_pass 127.0.0.1:13521;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /web-boke/html$fastcgi_script_name;
include fastcgi_params;
}
location = /wp-config.php {
deny all;
}
location ~* ^/wp-includes/.*\.(php|phps)$ {
internal;
}
location ~* ^/wp-content/.*.(txt|md|exe|sh|bat)$ {
deny all;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location ~ /\. {
deny all;
}
location /nginx_status {
stub_status on;
access_log on;
#allow 127.0.0.1;
allow all;
deny all;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:13521;
#auth_basic "close test passwd";
#auth_basic_user_file /web-boke/ssl-ca/login-radius;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /web-boke/html$fastcgi_script_name;
include fastcgi_params;
}
}
如果文章对你有帮助,欢迎点击上方按钮打赏作者
暂无评论