nginx.conf配置文件详解:
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx.conf配置文件详解:相关的知识,希望对你有一定的参考价值。
[[email protected] nginx]# vim /etc/nginx/nginx.conf
user nginx nginx; #nginx启动的用户
worker_processes 6; #如果负载以cpu密集型应用为主,如SSL或压缩应用,则worker数应与cpu数相同。
error_log /var/log/nginx/error.log; nginx错误日志存放路径
error_log /var/log/nginx/error.log notice;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx/nginx.pid; #pid存放路径
events {
use epoll; #linuxy一般使用epoll
worker_connections 65530; #cpu个数多,应该加大,并打开本机的连接数限制
}
http {
#vhost/*.conf
include mime.types; #指定包含的文件,如:include vhost/*.conf;
default_type application/octet-stream;
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ #nginx日志格式;可根据实际情况修改
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log /var/log/nginx/access.log main; #nginx访问日志路径
sendfile on;
tcp_nopush on; #不做推送
keepalive_timeout 65; #长连接,超时时间
client_body_buffer_size 512k;
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
gzip on; #先压缩,在发送,节省带宽
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
upstream www.cqelpay.com { #nginx负载均衡
server 192.168.11.38:8081 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.11.34:8080 weight=1 max_fails=2 fail_timeout=30s;
server 127.0.0.1:8080 backup; #当前面两个负载主机都宕机后,会启动这个错误页面
}
server { #每一个server对应一个虚拟主机
listen 80; #监听端口
server_name www.cqelpay.com; #域名
#charset koi8-r;
location / { #URI
# root html; #相对于nginx默认安装的访问路径
# index index.html index.jsp; #主页面
proxy_pass http://www.cqelpay.com;
}
#访问所有已下面图片或文件结尾的,过期实际为1天
location ~ .*\. (htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{
expires 1d;
}
#访问所有已下面图片或文件结尾的,过期时间为1小时
location ~ .*\.(js|css)?$
{
expires 1h;
}
log_format access ‘$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 access;
}
}
[[email protected] nginx]#
本文出自 “山猫” 博客,谢绝转载!
以上是关于nginx.conf配置文件详解:的主要内容,如果未能解决你的问题,请参考以下文章