一 查询 ps -ef|grep nginx
root 9612 9519 0 10:50 pts/8 00:00:00 grep nginx
root 21255 41822 0 Mar15 ? 00:01:06 nginx: worker process
root 21256 41822 0 Mar15 ? 00:01:06 nginx: worker process
root 21257 41822 0 Mar15 ? 00:01:16 nginx: worker process
root 21258 41822 0 Mar15 ? 00:01:19 nginx: worker process
root 41822 1 0 Jan24 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
二 执行 cat /etc/nginx/nginx.conf
user root root;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 10240;
}
http {
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
}
1. 运行用户
user root root;
2 启动进程
worker_processes auto;
这样nginx会自动根据核心数为生成对应数量的worker进程。(通常设置成和cpu的数量相等)
可用的核心数: lscpu 或者
cat /proc/cpuinfo | grep 'processor' | wc -l
3 全局错误日志及PID文件
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
4 加载动态模块
include /usr/share/nginx/modules/*.conf nginx -v nginx version: nginx/1.10.2 cd /usr/share/nginx/modules/ ls mod-http-geoip.conf mod-http-perl.conf mod-mail.conf mod-http-image-filter.conf mod-http-xslt-filter.conf mod-stream.conf cat mod-http-geoip.conf load_module "/usr/lib64/nginx/modules/ngx_http_geoip_module.so"; cat mod-mail.conf load_module "/usr/lib64/nginx/modules/ngx_mail_module.so";
5. 设定http服务器
http {
application/octet-stream
这个类型会让浏览器认为响应是普通的文件流,并提示用户下载文件
}