Nginx文件目录
1./etc/logrotate.d/nginx 配置文件,Nginx日志轮询,用于logrotate服务的日志切割
2./etc/nginx;/etc/nginx/nginx.conf;/etc/nginx/conf.d;/etc/nginx/conf.d/default.conf(默认不做更改是这个配置文件生效) ,目录配置文件,这些是Nginx的主配置文件
3./etc/nginx/fastcgi_params;/etc/nginx/uwsgi_params;/etc/nginx/scgi_params; 配置文件,cgi配置相关,fastgi配置
4./etc/nginx/koi-utf;/etc/nginx/koi-win/;/etc/nginx/win-utf; 配置文件,编码转换映射转换文件
5./etc/nginx/mime.types 配置文件,设置http协议的Content-Type与扩展名对应关系
6./usr/lib/systemd/system/nginx-debug.service;/usr/lib/systemd/nginx.service;/etc/sysconfig/nginx;/etc/sysconfig/nginx-debug;配置文件,用于配置出系统守护进程管理器的管理方式区别于CentOS6的/etc/init.d/的进程管理方式
7./usr/lib64/nginx/modules;/etc/nginx/modules 目录,Nginx模块目录
8./usr/sbin/nginx;/usr/sbin/nginx-debug 命令,Nginx服务的启动管理和终端命令
9./usr/share/doc/nginx-1.16.1;/usr/share/doc/nginx-1.16.1/COPYRIGHT;/usr/share/man/man8/nginx.8.gz 文件目录,Nginx的手册和帮助文件
10./var/cache/nginx 目录 Nginx的缓存目录
11./var/log/nginx 目录 Nginx的日志目录
Nginx编译模块
[root@pent ~]# nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --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 --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 --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
安装编译参数
--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执行对应模块时Nginx所保留的临时性文件
--user=nginx
--group=nginx
设定Nginx进程启动的用户和组用户
--with-cc-opt=parameters
设置额外的参数将被添加到CFLAGS变量
--with-ld-opt=parameters
设置附加的参数,链接系统库
nginx.conf配置内容
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
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;
}
default.conf配置内容
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;
#}
}
配置参数讲解
1.user -> 设置nginx服务是使用系统中哪个用户来启动
2.worker_processes -> 工作的进程数量
3.error_log -> nginx的错误日志
4.pid -> nginx服务启动时候的pid
5.events -> worker_connections-每个进程允许的最大连接数 use-工作的进程数
nginx的http配置语法
server {
listen 80; # 监听的服务端口
server_name localhost; # 可以配置多个server,可以配置独立域名,虚拟主机
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; # 具体访问的位置
}
}
启动&停止&重启nginx
systemctl start nginx.service
systemctl stop nginx.service
systemctl restart nginx.service
systemctl reload nginx.service
总结:
Nginx 的配置参数和启动数据信息,对于大部分后台开发人员来说是十分重要和关键的,也是深入了解系统流量的一个很好的入口网关设计实现,其中的配置也十分重要呢!