1、nginx 配置文件
1.nginx.conf.default
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#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;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html 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;
}
# 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_params;
#}
# 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;
# }
#}
}
2.配置说明:
user nobody
nginx 运行用户。默认nobody,nobody 是系统用户,是一个不能登陆的帐号,一个特殊用途的用户 ID ;值得注意的是,该处的 user 的访问权限应大于等于配置文件中 root 指向的文件(夹)的访问权限,否则可能出现 nginx 403 错误;
worker_processes 1
表示工作进程的数量,其默认值为1,意味着只运行一个worker。 我们应根据服务器可用内核数,磁盘,网络子系统等属性调整最佳值,常将值设置为可用的核心数。
或者,可以将其设置为auto。 这样nginx会自动根据核心数为生成对应数量的worker进程。
我们使用命令 grep -c processor /proc/cpuinfo 查看该服务器的核心数是4,将配置文件中worker_processes 的值设置为 auto 后,使用 ps -ef | grep nginx 查看 nginx 的工作进程数量和核心数一致;
再者,master 进程 与 worker 进程, 简单的来说master管理worker、分配任务,worker处理任务;更深层次的理解请移步nginx官方文档 及 master–worker模式;
error_log logs/error.log
nginx 错误日志 及其位置, 默认位置一般和 /conf 文件夹同级的 /logs 文件夹中;
在 http 模块中同样也有access日志的相关配置:
log_format main 将输出日志格式化,便于查阅,可根据日志变量设置合适的日志格式;
worker_connections 1024
这个参数表示每个进程允许的最多连接数,理论上每台nginx服务器的最大连接数为 worker_processes * worker_connections;当然这个值的设定还和目前该linux系统里打开文件描述符的最大值(使用 ulimit -n 命令查看)相关;
======================================================================