nginx 一般配置实例 静态页面

时间:2025-01-20 22:36:20
# 使用的用户和组
user www www;
# 指定工作衍生进程数(一般等于CPU的总核数或总核数的两倍,例如两个四核CPU,则总核数为8)
worker_processes 8;
# 指定错误日志存放的路径,错误日志记录级别可选项为:[ debug | info | notice | warn | error | crit ]
error_log /data1/logs/nginx_error.log crit;
# 指定 pid 存放的路径
pid /usr/local/webserver/nginx/nginx.pid; # 指定文件描述符数量
worker_rlimit_nofile 51200; events
{
# 使用的网络I/O模型,Linux系统推荐采用epoll模型,FreeBSD系统推荐采用kqueue模型
use epoll; # 允许的连接数
worker_connections 51200;
} http
{
include mime.types;
default_type application/octet-stream;
# 设置使用的字符集,如果一个网站有多种字符集,请不要随便设置,应让程序员在HTML代码中通过Meta标签设置
#charset gb2312; server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k; # 设置客户端能够上传的文件大小
client_max_body_size 8m; sendfile on;
tcp_nopush on; keepalive_timeout 60; tcp_nodelay on; fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
# 开启gzip压缩
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; #limit_zone crawler $binary_remote_addr 10m; server
{
listen 80;
server_name www.yourdomain.com yourdomain.com;
index index.html index.htm index.php;
root /data0/htdocs; #limit_conn crawler 20; location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
} 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 /data1/logs/access.log access;
}
}