Nginx01-Nginx基本配置

nginx配置文件详解
https://blog.csdn.net/wangbin_0729/article/details/82109693

nginx架构

master/worker结构
    一个master进程:负责负载加载和分析配置文件、管理worker进程、平滑升级
    一个或多个worker进程:负责处理并响应用户请求
缓存相关进程:
    cache loader     加载缓存对象
    cache manager    管理缓存对象

配置文件构成

主配置文件 nginx.conf
子配置文件 include conf.d/*.conf (在主配置文件中有设定)

主配置文件结构

main         # 主配置段,即全局配置段,位于文件最开头部分
http {}      # http/https协议相关配置段

http {} 语句块中包含 server {}
server {} 语句块中包含 location {} 和 upstream {}

server语句块     用于定义虚拟主机
location语句块   用于匹配网页位置,控制网页目录的权限
upstream语句块   用于负载均衡

http协议相关配置结构

http {
    xxxxxxx
    xxxxxxx               # 上边这段为各server的公共配置
    server {              # 每个server为一个虚拟主机
        xxxxxxxx
    }
    server {
        server_name       # 虚拟主机名
        root              # 主目录
        alias             # 路径别名
        location [operator] url { # 指定url特性
            if CONDITION {
            }
        }
    }
}

nginx日志格式

/usr/local/nginx/logs/access.log

time_local    本地时间戳
host          请求host地址
remote_addr   远程请求地址
request       请求uri
request_time  整个请求的总时间
body_bytes_sent  请求文件内容大小
status           http请求状态
upstream_addr    后台提供服务的地址(即转发处理的目标地址)
upstream_reponse_time  请求时,upstream的响应时间
upstream_status  upstream状态
http_refer       url跳转来源
http_user_agent  用户终端浏览器的UserAgent

源码安装nginx

yum -y install  gcc  pcre-devel  openssl-devel
useradd -s  /sbin/nologin  nginx
tar -xf nginx-1.10.3.tar.gz
cd  nginx-1.10.3
./configure   \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-stream \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module
make && make install

查看nginx支持的模块

./configure --help

安装后的目录结构

ls /usr/local/nginx

conf:  配置文件
html:网页文件
logs:日志
sbin:主程序

nginx常用命令

ln -s /usr/local/nginx/sbin/nginx /sbin/

nginx -s stop # 强制停止
nginx -s quit # 停止监听端口,停止接收新连接,处理完手头连接再停止
nginx -s reload
nginx -h  # 查看帮助
nginx -t  # 检查配置文件语法

kill -s SIGQUIT <nginx master pid>
kill -s SIGWINCH <nginx worker pid>
posted @ 2024-05-11 15:35  立勋  阅读(19)  评论(0)    收藏  举报