nginx.conf 配置

http {
#主模块指令,实现对配置文件所包含的文件的设定,可以减少主配置文件的复杂度
include mime.types;

#核心模块指令,默认设置为二进制流,也就是当文件类型未定义时使用这种方式
default_type application/octet-stream;

#下面代码为日志格式的设定,main为日志格式的名称,可自行设置,后面引用
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#引用日志main格式
access_log logs/access.log main;

#设置允许客户端请求的最大的单个文件字节数
client_max_body_size 20M;
#指定来自客户端请求头的headebuffer大小
client_header_buffer_size 32k;
#指定连接请求试图写入缓存文件的目录路径
client_body_temp_path /dev/shm/client_body_temp;
#指定客户端请求中较大的消息头的缓存最大数量和大小,目前设置为4个32KB
large client_header_buffers 4 32k;

#开启高效文件传输模式
sendfile on;
#开启防止网络阻塞
tcp_nopush on;
#开启防止网络阻塞
tcp_nodelay on;

#设置客户端连接保存活动的超时时间
#keepalive_timeout 0; # 无限时间
keepalive_timeout 65;

#设置客户端请求读取header超时时间
client_header_timeout 10;
#设置客户端请求body读取超时时间
client_body_timeout 10;

#HttpGZip模块配置
#开启gzip压缩
gzip on;
#设置允许压缩的页面最小字节数
gzip_min_length 1k;
#申请4个单位为16K的内存作为压缩结果流缓存
gzip_buffers 4 16k;
#设置识别http协议的版本,默认为1.1
gzip_http_version 1.1;
#指定gzip压缩比,1-9数字越小,压缩比越小,速度越快
gzip_comp_level 2;
#指定压缩的类型
gzip_types text/plain application/x-javascript text/css application/xml;
#让前端的缓存服务器进过gzip压缩的页面
gzip_vary on;

# server配置
server {

}
}

 


server {
#单连接请求上限次数
keepalive_requests 120;
#监听端口
listen 88;
#监听地址,可以是ip,最好是域名
server_name 111.222.333.123;
#server_name www.123.com;
#设置访问的语言编码
charset utf-8;
#设置虚拟主机访问日志的存放路径及日志的格式为main
access_log /www/wwwlogs/111.222.333.123.log main; #响应日志
error_log /www/wwwlogs/111.222.333.123.log main; #错误日志

#PHP-INFO-START PHP引用配置,可以注释或修改
include enable-php-74.conf;
#PHP-INFO-END

#REWRITE-START URL重写规则引用
include /www/server/panel/vhost/rewrite/111.222.333.123.conf;
#REWRITE-END

#设置主机基本信息
#请求的url过滤,正则匹配,~为区分大小写,~*为不区分大小写。
location ~*^.+$ {
#根目录
root html;
#设置默认页
index index.html index.htm;
#拒绝的ip,黑名单
deny 127.0.0.1;
#允许的ip,白名单
allow 172.18.5.54;
}

#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}

#SSL证书验证目录相关设置
location ~ \.well-known{
allow all;
}

#图片资源配置
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log /dev/null;
access_log off;
}

#网站js与css资源配置
location ~ .*\.(js|css)?$
{
expires 12h;
error_log /dev/null;
access_log off;
}

#访问异常页面配置
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

 


实例配置
worker_processes auto; //工作进程数 默认1 auto自动 可以看CPU核心(线程)数来定义
worker_cpu_affinity auto; //分配的CPU进程参数
error_log /var/log/nginx/error.log crit;
pid /var/run/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200; //设置一个 worker 进程所能打开的最多文件数量
user root;
events { // events 模块主要是nginx 和用户交互网络连接优化的配置内容
use epoll;//使用epoll 的I/O 模型
worker_connections 51200;//每个进程允许的最多连接数, 理论上每台nginx 服务器的最大连接数为worker_processes*worker_connections。
multi_accept off;//默认off 设置单个工作进程是否允许同时接受多个网络连接
accept_mutex off;//得到一个新连接 是否唤醒所有worker 或者只唤醒一个 唤醒所有worker也只能有一个可以获取连接
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;//指定来自客户端请求头的headebuffer大小
large_client_header_buffers 4 32k;//指定客户端请求中较大的消息头的缓存最大数量和大小,目前设置为4个32KB
#client_max_body_size 50m;
sendfile on;//开启高效文件传输模式
sendfile_max_chunk 512k;
tcp_nopush on;//开启防止网络阻塞
keepalive_timeout 15;//设置客户端连接保存活动的超时时间
tcp_nodelay on;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent $request_time "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

gzip on; //Gzip压缩功能
gzip_min_length 1k;
gzip_buffers 4 16k; //缓存空间的个数
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
#limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
server_tokens off;
access_log off;

# security conf
add_header X-Content-Type-Options: nosniff; //通过add_header后会返回给客户端两个同样的header头
add_header X-XSS-Protection "1; mode=block";
add_header X-Frame-Options SAMEORIGIN;
# add_header Content-Security-Policy "default-src 'self'";
# add_header Strict-Transport-Security "max-age=63072000; includeSubdomains; preload";
add_header X-Permitted-Cross-Domain-Policies 'master-only';
add_header Referrer-Policy 'origin';

proxy_connect_timeout 300s; //代理服务器的配置
proxy_send_timeout 900;
proxy_read_timeout 900;
proxy_buffer_size 32k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_redirect off;
proxy_hide_header Vary;
proxy_set_header Accept-Encoding '';
proxy_set_header Host $http_host;
proxy_set_header Referer $http_referer;
proxy_set_header Cookie $http_cookie;
# proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

#include vhost/*.conf;
# 非root用户启动请注释这个server
#server {
# listen 80 default;
# return 403;
#}

upstream aisitebackend {
ip_hash;
# 按服务IP 端口修改
server 10.52.21.163:8080 max_fails=3 fail_timeout=30s;
server 10.52.21.164:8080 max_fails=3 fail_timeout=30s;
#server appip2:8080 max_fails=3 fail_timeout=30s;
}

upstream searchbackend {
ip_hash;
# 按服务IP 端口修改
server 10.52.21.161:8080 max_fails=3 fail_timeout=30s;
server 10.52.21.162:8080 max_fails=3 fail_timeout=30s;
#server searchip2:8080 max_fails=3 fail_timeout=30s;
}

upstream static_backend {
server localhost:80;
}
server
{
listen 80;
listen [::]:80 ipv6only=on;
# server_name域名配置必须要进行配置实际IP或域名
server_name 10.52.38.132;
root /data/static;
index jlbank/index.html index.html;
charset utf-8;
ssi on;
ssi_silent_errors on;
ssi_types text/shtml;

if ($http_x_forwarded_proto = http){
rewrite ^(.*) https://$host$1 permanent;
}

client_max_body_size 10M;
location / {
expires 5m;
}



location /eportal {proxy_pass http://aisitebackend/eportal;}
location /eportalapp {proxy_pass http://aisitebackend/eportalapp;}
location /eportalmsg {proxy_pass http://aisitebackend/eportalmsg;}
location /eportalsite {proxy_pass http://aisitebackend/eportalsite;}
location /eportalapply {proxy_pass http://aisitebackend/eportalapply;}
location /search {proxy_pass http://searchbackend/search;}
location = /search/admin/toLogin.htm {
try_files $uri /jlbank/index.html =404;
}
# 生产配置日志必要配置
access_log logs/default.log;

error_page 405 =200 @405;
location @405 {
root /srv/http;
proxy_method GET;
proxy_pass http://static_backend;
}

}
}

posted @ 2023-05-18 14:21  zzzzxb  阅读(99)  评论(0)    收藏  举报