nginx配置文件

#user  nobody;
#程序运行用户和组
worker_processes
1; #启动进程,指定nginx 启动的工作进程数量,建议按照cpu数目来指定,一般等于cpu核心数目

#error_log logs
/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #全局错误日志
#pid logs
/nginx.pid; #主进程PID 保存文件


worker_rlimit_nofile 51200;
#文件描述符数量
events {
use epoll;
#使用epoll模型,对于2.6以上的内核,建议使用epoll模型提高性能
worker_connections
1024;
#工作进程的最大连接数量,根据硬件调整,和前面的工作进程配合使用,尽量大,但是不要把CPU 跑到 100% 就行,每个进程允许的最多连接数,
#理论上每台nginx 服务器的最大连接数为worker_processes*worker_connections,具体还要看服务器的硬件、带宽等 } http {
#整体环境配置-网站配置 include mime.types; default_type application
/octet-stream; #设定mime类型,文件传送类型由 mime.type 文件定义
#log_format main
'$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
#定义日志格式
    server_names_hash_bucket_size 128;
#保存服务器名字的hash表大小
client_header_buffer_size 32k;
#客户端请求头部缓冲区大小
large_client_header_buffers 4 32k;
#最大客户端头缓冲区大小
client_max_body_size 50m;
#客户端最大上传文件大小(M)
sendfile on;
#sendfile 指令指定 nginx 是否调用 sendfile 函数来输出文件,对于普通应用,必须为on。
#如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的uptime #tcp_nopush on;
#默认,作用是数据包不会马上传送出去,等到数据包最大时,一次性的传输出去,这样有助于解决网络堵塞。(只有在 sendfile on 时有效)
tcp_nodelay on;
#禁用nagle算法,也即不缓存数据。有效解决网络阻塞
#sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #连接超时时间

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 256k;
#fastcgi 设置
gzip on; 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]\.";

server_tokens off;
#隐藏nginx版本号(curl -I 192.168.80.129 可以查看,更安全)
server { listen
80;
#监听80端口,web服务的监听设置,可以采用"ip地址:端口"的形式 server_name localhost; #服务器名,可以写多个域名,用空格隔开 #charset koi8
-r; #access_log logs/host.access.log main; #正确访问日志
location
/ { root html;
#网页目录 index index.html index.php index.htm;
#默认网页文件 } #error_page
404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location /nginx_status {
stub_status on;
access_log off;
}
#开启status状态监测

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ {
expires 30d;
}
#静态文件处理,保存日期30天
location ~ .*\.(js|css)?$ {
expires 12h;
}
#js和css文件处理,保存期12小时 # proxy the PHP scripts to Apache listening on
127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; } #解析php文件设置 # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} include vhost/*.conf;
#vhost/目录下配置文件生效
}
posted @ 2019-12-16 16:43  一窗明月半帘风  阅读(177)  评论(0编辑  收藏  举报