资讯专栏INFORMATION COLUMN

Nginx深入了解-基础(二)

Hegel_Gu / 3003人阅读

yum安装nginx后可通过命令rpm -pl nginx查看相关的安装目录。如下:
路径 类型 作用
/etc/logrotate.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 配置文件 cgi配置相关,fastcgi配置
/etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf 配置文件 编码转换映射转换文件
/etc/nginx/mime.types 配置文件 设置http协议的content-type与扩展名对应关系
/usr/lib/systemd/system/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 命令 nginx服务的启动管理的终端命令
/usr/share/doc/nginx-版本号 /usr/share/doc/nginx-版本号/COPYRIGHT /usr/share/man/man8/nginx.8.gz 文件、目录 nginx手册、帮助文件
/var/cache/nginx 目录 nginx的缓存目录,nginx布景可以用作服务代理,还可以用来做缓存服务
/var/log/nginx 目录/nginx日志目录

使用nginx -V查看配置参数:

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 安装目的目录或路径
--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进程启动的用户和用户组
nginx.conf的配置相关

第一块:

参数 说明
user 设置nginx服务的系统使用用户
worker_processes 工作进程数,与cpu核数保持一致
error_log nginxd的错误日志
pid nginx服务启动时候的pid

第二块:

模块 参数 说明
events worker_connections 每个进程允许最大连接数
use 工作进程数

第三块:

http {
    include       /etc/nginx/mime.types; // http的content-type设置
    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;
    // 标准的方式是将多个server配置成多个.conf文件放在/etc/nginx/conf.d下include进来
    #include /etc/nginx/conf.d/*.conf;
    server {
        listen 80;
        server_name localhost;
        
        localtion / {
            root ....
            index ....
        }
        
        error_page ....
        localtion = /50x.tml {
            .....
        }
    }
    
    server {
        ....
    }
    server {
        ....
    }
}

log_format定义access_log的日志内容格式,可自定义。例如添加user_agent信息:$http_User_Agent.

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/40034.html

相关文章

  • PHP程序员学习路线

    摘要:第一阶段基础阶段基础程序员重点把搞熟练核心是安装配置基本操作目标能够完成基本的系统安装,简单配置维护能够做基本的简单系统的开发能够在中型系统中支持某个功能模块的开发。本项不做重点学习,除非对前端有兴趣。 第一阶段:基础阶段(基础PHP程序员) 重点:把LNMP搞熟练(核心是安装配置基本操作) 目标:能够完成基本的LNMP系统安装,简单配置维护;能够做基本的简单系统的PHP开发;能够在P...

    genedna 评论0 收藏0
  • Nginx深入了解-基础(四)

    摘要:方式二结合模块方式三通过自定义变量传递官方文档使用文件密码信息按照官网可以使用方式生成对应的文件配置局限性一,用户信息依赖文件二,操作管理机械,效率低下解决方式一,使用实现验证二,和打通,利用模块 Nginx的访问控制。有两种方式可以来进行webserver的访问控制:一种是基于IP的访问控制-http_access_module;另一种是基于用户的信任登录-http_auth_bas...

    EddieChan 评论0 收藏0
  • 写这么多系列博客,怪不得找不到女朋友

    摘要:前提好几周没更新博客了,对不断支持我博客的童鞋们说声抱歉了。熟悉我的人都知道我写博客的时间比较早,而且坚持的时间也比较久,一直到现在也是一直保持着更新状态。 showImg(https://segmentfault.com/img/remote/1460000014076586?w=1920&h=1080); 前提 好几周没更新博客了,对不断支持我博客的童鞋们说声:抱歉了!。自己这段时...

    JerryWangSAP 评论0 收藏0
  • 如何"有计划,高效率,优简历"应对面试

    摘要:虽然有了十全的计划,但如何高效率去记住上面那么多东西是一个大问题,看看我是怎么做的。 前言 前一篇文章讲述了我在三月份毫无准备就去面试的后果,一开始心态真的爆炸,但是又不服气,一想到每次回来后家人朋友问我面试结果的期待脸,越觉得必须付出的行动来证明自己了。 面经传送门:一个1年工作经验的PHP程序员是如何被面试官虐的? 下面是我花费两个星期做的准备,主要分三部分: 有计划——计划好...

    gyl_coder 评论0 收藏0

发表评论

0条评论

Hegel_Gu

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<