Nginx最佳实践记录-安装后默认配置参数讲解

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的日志目录

编译模块参数

[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
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 岁月如诗,谱写了一首动人的诗 岁月如歌,演奏了一曲动听的歌 岁月如画,描绘了一副精美的画 在人生的旅途中,...
    麦盖提650张文宽阅读 1,172评论 4赞 6
  • 像夜里一滴雨 贮藏在冰凉的梦里 不让她风化,不让她失落…… 2019年2月11日
    五月传奇阅读 481评论 4赞 12
  • 每天早上5点起床。做饭洗衣收拾卫生 。成了固定的模式。 每天早上做三次饭,变着花样做吧!只要孩子们爱吃...
    会飞的抱抱阅读 188评论 0赞 1
  • 终于 你来到这个世界一周了 我在看到你几天后 就离开了 去遥远的南方 这边比家里冷 终于 你看到所有我的亲戚了 不...
    布老头和他的家人们阅读 182评论 0赞 0
  • 2017年就这样过完了,我们总是在时间流逝后感叹时间都去哪了 回首这一年,感恩所有的亲人朋友一路的陪伴与相随 这一...
    成莉cl阅读 183评论 0赞 0

友情链接更多精彩内容