----------------------------------nginx 配置优化--------------------------------------------------
httpd:
#gzip
#并发请求:limit_req_zone,并发链接:limit_conn_zone 设置
#隐藏版本号
server_tokens off;# json格式的日志
log_format main_json '{
"@timestamp":"$time_iso8601",
"host":"$server_addr",
"clientip":"$remote_addr",
"remote_user":"$remote_user",
"request":"$request",
"http_user_agent":"$http_user_agent",
"size":"$body_bytes_sent",
"responsetime":"$request_time",
"upstreamtime":"$upstream_response_time",
"upstreamhost":"$upstream_addr",
"http_host":"$host",
"url":"$uri",
"domain":"$host",
"xff":"$http_x_forwarded_for",
"referer":"$http_referer",
"status":"$status",
"body":"$request_body",
}';#隐藏X-Powered-By:PHP
#方法一:在php.ini文件关闭expose_php = On改成 expose_php = Off
#大约在370行,把expose_php = On 改成expose_php = Off
#重新加载nginx配置文件,重启php,让配置生效
#隐藏X-Powered-By:PHP
#方法二 :在nginx配置文件.location添加:fastcgi_hide_header X-Powered-By;
server{listen 80;
listen 443 ssl;
server_name xxx;
ssl_certificate ssl_key/xxx.pem;
ssl_certificate_key ssl_key/dxxx.key;
root "/xxx";
location / {
index index.php index.html error/index.html;
autoindex off;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location /status {
stub_status on;
access_log off;
}location = /favicon.ico {
log_not_found off;
access_log off;
}
location ~ \.php(.*)$ {
#fastcgi_hide_header X-Powered-By;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
error_log /var/log/nginx/xxx_error.log crit;
access_log /var/log/nginx/xxx_acess.log main_json;location ~* \.(ico|jpe?g|gif|png|bmp|swf|flv)$ {
expires 30d;
log_not_found off;
access_log off;}
location ~* \.(js|css)$ {
expires 7d;
log_not_found off;
access_log off;
}}