nginx配置文件详解


nginx配置文件详解



产品型号:Thinkpad E15
系统版本:centos8
nginx配置文件详解
#定义Nginx运行的用户和用户组
user nginx nginx;
#nginx进程数, 建议设置为等于CPU总核心数 。
worker_processes 8;
#全局错误日志定义类型, [ debug | info | notice | warn | error | crit ]
error_log /var/log/nginx/error.log info;
#进程文件
pid /var/run/nginx.pid;
#一个nginx进程打开的最多文件描述符数目, 理论值应该是最多打开文件数(系统的值ulimit -n)与nginx进程数相除, 但是nginx分配请求并不均匀, 所以建议与ulimit -n的值保持一致 。
worker_rlimit_nofile 65535;
#设定http服务器
http
{
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型
#charset utf-8; #默认编码
server_names_hash_bucket_size 128; #服务器名字的hash表大小
client_header_buffer_size 32k; #上传文件大小限制
large_client_header_buffers 4 64k; #设定请求缓
client_max_body_size 8m; #设定请求缓
autoindex on; #开启目录列表访问, 合适下载服务器, 默认关闭 。
tcp_nopush on; #防止网络阻塞
tcp_nodelay on; #防止网络阻塞
keepalive_timeout 120; #长连接超时时间, 单位是秒
#gzip模块设置
gzip on; #开启gzip压缩输出
gzip_min_length 1k; #最小压缩文件大小
gzip_buffers 4 16k; #压缩缓冲区
gzip_http_version 1.0; #压缩版本(默认1.1, 前端如果是squid2.5请使用1.0)
gzip_comp_level 2; #压缩等级
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m; #开启限制IP连接数的时候需要使用
#虚拟主机的配置
server
{
#监听端口
listen 80;
#域名可以有多个, 用空格隔开
server_name www.ha97.com ha97.com;
index index.html index.htm index.php;
root /data/www/ha97;
location ~ .*.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
#图片缓存时间设置
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 10d;
}
#JS和CSS缓存时间设置
location ~ .*.(js|css)?$
{
expires 1h;
}
#定义本虚拟主机的访问日志
access_log /var/log/nginx/ha97access.log access;
#对 “/” 启用反向代理
location / {
proxy_pass http://127.0.0.1:88;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
【nginx配置文件详解】proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    推荐阅读