在本文中将介绍Nginx的基本参数,包括Nginx的安装目录,编译时的编译参数以及默认配置。
Nginx安装目录
查看安装目录
初学者安装完Nginx有些懵逼,安装到哪里去了?如果您是使用yum进行安装那么可以使用rpm -ql nginx
进行查看。它将列出Nginx的所有安装目录。
安装目录介绍
目录 | 类型 | 作用 |
/etc/lograotage.d/nginx | 配置文件 | Nginx日志轮转,用于logrotate服务的日志切割配置 |
/etc/nginx /etc/nginx/nginx.conf /etc/nginx/conf.d /etc/nginx/conf.d/default.conf |
目录,配置文件 | Nginx主配置文件(重点关注) |
/etc/nginx/fastcgi_params /etc/nginx/uwsgi_params /etc/nginx/scgi_params |
配置文件 | fastcgi,cgi配置相关 |
/etc/nginx/mime.types | 配置文件 | 设置http协议的Content-Type与扩展名对应关系 |
/etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx-win-utf |
配置文件 | 编码转换映射文件 |
/usr/lib/systemd/nginx-debug.service /usr/lib/systemd/system/nginx.service /etc/sysconfig/nginx /etc/sysconfig/nginx-debug |
配置文件 | 配置系统守护进程管理器管理方式 |
/usr/lib64/nginx/modules /etc/nginx/modules |
目录 | Nginx模块目录 |
/usr/sbin/nginx /usr/sbin/nginx-debug |
命令 | 设置http协议的Content-Type与扩展名对应关系 |
/usr/share/doc/nginx-1.16.1 /usr/share/doc/nginx-1.16.1/COPYRIGHT /usr/share/man/man8/nginx.8.gz |
文件、目录 | Nginx手册和帮助文件 |
/var/cache/nginx | 目录 | Nginx的缓存目录 |
Nginx编译参数
安装完Nginx后我们可以使用Nginx -V
查看安装编译参数。
编译参数 | 作用 |
--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock |
Nginx安装的目录和相关配置文件目录 |
--http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp |
执行对应模块时Nginx所保留的临时性文件 |
--user=nginx --group=nginx |
设定Nginx进程启动的用户和组用户,为了安全嘛 |
--with-cc-opt=parameters | 设置额外的参数将被添加到CFLAGS变量 |
--with-ld-opt=parameters | 设置附加的参数,链接系统库 |
默认配置
进入/etc/nginx
目录,浏览nginx.conf
这一配置文件,了解Nginx的默认配置语法。
#设置nginx服务的系统使用用户
user nginx;
#工作进程数
worker_processes 1;
#nginx的错误日志
#warn 错误日志级别
error_log /var/log/nginx/error.log warn;
#nginx服务启动时候的pid
pid /var/run/nginx.pid;
#events: 事件模块
#worker_connections: 每个进程运行最大连接数
events {
worker_connections 1024;
}
#http模块(重点),可包含多个server(站点)
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方式传输
sendfile on;
#tcp_nopush on;
#客户端和服务端连接超时时间
keepalive_timeout 65;
#开启gzip压缩
#gzip on;
#引入/etc/nginx/conf.d/目录下的索引conf文件
include /etc/nginx/conf.d/*.conf;
}
由于配置了/etc/nginx/conf.d/*.conf
,同时打开default.conf
文件。
server {
#监听端口号
listen 80;
#站点名称
server_name localhost;
#配置访问路径
location / {
root /usr/share/nginx/html;#根目录路径
index index.html index.htm;#默认页面名称
}
#重定向到错误页面
error_page 500 502 503 504 /50x.html;
#配置错误页面路径
location = /50x.html {
root /usr/share/nginx/html;
}
}
版权属于:带翅膀的猫
本文链接:https://www.chengpengper.cn/archives/54/
转载时须注明出处及本声明