目录结构:
/etc/logrotate.d/nginx :日志文件定时切割处理,nginx使用自动切割程序 logrotate(其配置文件是/etc/logrotate.conf)这个目录里的配置也会被logrotate加载。
/etc/nginx 配置文件
/etc/nginx/conf.d 配置文件
/etc/nginx/conf.d/default.conf 配置文件
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types 定义nginx可以处理哪些媒体资源类型
/etc/nginx/modules
/etc/nginx/nginx.conf 配置文件
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx 命令文件
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.18.0
/usr/share/doc/nginx-1.18.0/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html 站点目录
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx 日志文件
1、/etc/nginx/nginx.conf
[root@localhost nginx]# cat nginx.conf
user nginx; 定义管理worker服务的用户
worker_processes 1; 定义几个worker进程,一般配置为CPU核数。master_processes管理服务正常运行,worker_processes正真处理用户请求(杀死worker进程不会正真停止nginx服务。)
error_log /var/log/nginx/error.log warn; 错误日志
pid /var/run/nginx.pid; 记录进程ID
#########################################################
events {
worker_connections 1024; 定义一个worker进程可以同时接受的请求数量
}
#########################################################
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"'; 定义日志格式
access_log /var/log/nginx/access.log main; 定义日志路径并引用上述格式
sendfile on;
#tcp_nopush on;
keepalive_timeout 65; 连接超时时间
#gzip on;
include /etc/nginx/conf.d/*.conf; 加载配置文件
}
2、/etc/nginx/conf.d/default.conf
server { 网站的配置,一个server就是一个网站,也叫虚拟主机
listen 80; 监听端口
server_name localhost; 指定网站域名
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/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 /usr/share/nginx/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;
#}
}