nginx.conf
user nginx; #设置nginx服务的系统使用用户
worker_processes 1; #工作进程数(一般设置为当前机器CPU核数一致)
error_log /var/log/nginx/error.log warn; #nginx的错误日志
pid /var/run/nginx.pid; #nginx服务启动时候的pid
#events模块
events {
worker_connections 1024; #每个进程允许最大连接数
use epoll; #使用epoll的I/O 模型(如果你不知道Nginx该使用哪种轮询方法的话,它会选择一个最适合你操作系统的)
}
http {
include /etc/nginx/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"';
#nginx的访问日志
access_log /var/log/nginx/access.log main;
#sendfile 默认打开(上一章记录过)
sendfile on;
#tcp_nopush on;
#设置客户端与服务端超时时间
keepalive_timeout 65;
#gzip on;
#default.conf文件
include /etc/nginx/conf.d/*.conf;
}
default.conf
listen 80; #访问端口号
server_name localhost; #访问地址可以是域名/IP
location / { #以/匹配
root /usr/share/nginx/html; #默认访问的路径
index index.html index.htm; #默认访问的页面
}
[root@smoker-linux nginx]# nginx -t -c nginx.conf #测试nginx.conf文件是否正确
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@smoker-linux nginx]# nginx -s reload -c nginx.conf #重启NGINX